package hotel.compare.oversea.service.impl;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import hotel.base.oversea.constant.CommonConstants;
import hotel.base.oversea.constant.CommonUrlConstants;
import hotel.base.oversea.constant.enums.CommonEnums;
import hotel.base.oversea.constant.enums.CompareRequestUrlEnums;
import hotel.base.oversea.constant.enums.MessageEnums;
import hotel.base.oversea.constant.enums.SwitchChannelNameEnums;
import hotel.base.oversea.dto.meituan.MtRoomInfoDto;
import hotel.base.oversea.entity.MtHotelRoomVo;
import hotel.base.oversea.entity.master.CompareHotelBasicRoom;
import hotel.base.oversea.service.impl.BaseServiceImpl;
import hotel.base.oversea.utils.*;
import hotel.base.oversea.vo.meituan.request.goods.MtHotelGoodsParamVo;
import hotel.base.oversea.vo.meituan.request.goods.MtHotelGoodsVo;
import hotel.base.oversea.vo.meituan.request.room.MtHotelRealRoomVo;
import hotel.compare.oversea.config.service.RedisService;
import hotel.compare.oversea.entity.master.CompareHotel;
import hotel.compare.oversea.entity.master.CompareHotelRoom;
import hotel.compare.oversea.entity.master.CompareHotelRoomBySql;
import hotel.compare.oversea.entity.meituan.MtHotelRoom;
import hotel.compare.oversea.entity.switchs.*;
import hotel.compare.oversea.mapper.master.CompareHotelBasicRoomMapper;
import hotel.compare.oversea.mapper.master.CompareHotelMapper;
import hotel.compare.oversea.mapper.master.CompareHotelRoomBySqlMapper;
import hotel.compare.oversea.mapper.master.CompareHotelRoomMapper;
import hotel.compare.oversea.mapper.meituan.MtHotelRoomMapper;
import hotel.compare.oversea.mapper.switchs.*;
import hotel.compare.oversea.service.CompareHotelRoomService;
import hotel.compare.oversea.service.CompareRestTempaleUtilsService;
import hotel.compare.oversea.vo.CompareHotelRoomVo;
import hotel.compare.oversea.vo.GetRoomListVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.tomcat.util.threads.ThreadPoolExecutor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;

/**
 * @Author lmf
 * @Date 2020/5/29 13:57
 * 效验房型信息
 **/
@Slf4j
@Service
public class CompareHotelRoomServiceImpl extends BaseServiceImpl<CompareHotelBasicRoom> implements CompareHotelRoomService {


    @Autowired
    private RedisService redisService;
    @Autowired
    private CompareRestTempaleUtilsService compareRestTempaleUtilsService;
    @Autowired
    private CompareHotelRoomMapper compareHotelRoomMapper;

    @Autowired
    private CompareHotelMapper compareHotelMapper;

    @Autowired
    private CompareHotelBasicRoomMapper compareHotelBasicRoomMapper;

    @Autowired
    private MtHotelRoomMapper mtHotelRoomMapper;

    @Autowired
    private SwitchRoomTypeMapper switchRoomTypeMapper;

    @Autowired
    private SwitchBasicRoomTypeMapper switchBasicRoomTypeMapper;

    @Autowired
    private SwitchCreateSubHotelMapper switchCreateSubHotelMapper;
    @Autowired
    private CompareHotelRoomBySqlMapper compareHotelRoomBySqlMapper;

    @Autowired
    private SwitchCreateBasicRoomMapper switchCreateBasicRoomMapper;

    @Autowired
    private SwitchHotelUpMapper switchHotelUpMapper;

    //定义多线程启动相关配置
    final static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //定义线程池数量
    private static int corePoolSize=Runtime.getRuntime().availableProcessors();
    //corePoolSize：线程池持有的可用的线程数量
    //maximumPoolSize：当队列workQueue满了过后，线程池可用的最大线程数量
    private static ThreadPoolExecutor executor=new ThreadPoolExecutor(corePoolSize,Integer.MAX_VALUE,101, TimeUnit.SECONDS,new LinkedBlockingDeque<>(1000));
    private  Map<String, CompareHotel> compareHotels=new HashMap<>();
    private Map<Integer,Integer> pageMap;
    private Map<Integer,String> isCompareNumMap = new LinkedHashMap<>();
    private List<SwitchBasicRoomType> switchRoomTypes;
    private List<MtHotelRoom> mtHotelRooms;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private SwitchCreateRoomMapper switchCreateRoomMapper;

    //获取缓存价格配置
    private String priKey="switch_online_price_sets_up_by_"+ SwitchChannelNameEnums.CTRIP.getName();

    //价格比例
    private String priPre;


    //定义价格阶梯比例
    private List<Map<String,Object>> switchPriceBaseSetEntityByCtripChannel;

    /**
     * 校验房型
     * 1.获取酒店id
     * 2.获取酒店房型列表
     * 3.进行匹配
     * @return
     * 多线程运行:
     */
 /*   @Transactional
    public Result<Object> compareHotelRoomOld() {
        //针对某个酒店进行匹配
      *//*  SwitchBasicRoomType switchRoomType=new SwitchBasicRoomType();
        //母酒店id
        switchRoomType.setMasterHotelId(5253169);
        List<SwitchBasicRoomType> switchRoomTypes=switchBasicRoomTypeMapper.select(switchRoomType);
        //获取美团的房型列表
        MtHotelRoom mtHotelRoom=new MtHotelRoom();
        mtHotelRoom.setMtHotelId("6916778");
        List<MtHotelRoom> mtHotelRooms=mtHotelRoomMapper.select(mtHotelRoom);
        compareHotelRoomsByList(switchRoomTypes,mtHotelRooms);*//*
   *//*     redisService.set(CommonConstants.COMPARE_HOTEL_ID_NUMS,num+1);
        return new Result<>("对比任务完成");*//*
     *//*   for(;startIndex<400*(page+1);startIndex++){
            CompareHotel compareHotel=compareHotels.get(startIndex);
            log.info("=====获取的对比信息为========为{}",compareHotel);
            SwitchBasicRoomType switchRoomType=new SwitchBasicRoomType();
            //母酒店id
            switchRoomType.setMasterHotelId(compareHotel.getSwitchHotelId());
            List<SwitchBasicRoomType> switchRoomTypes=switchBasicRoomTypeMapper.select(switchRoomType);
            //获取美团的房型列表
            MtHotelRoom mtHotelRoom=new MtHotelRoom();
            mtHotelRoom.setMtHotelId(compareHotel.getMtHotelId());
            List<MtHotelRoom> mtHotelRooms=mtHotelRoomMapper.select(mtHotelRoom);
            compareHotelRoomsByList(switchRoomTypes,mtHotelRooms);
        }*//*
       *//* pages.set(page+1);
        redisService.set(CommonConstants.COMPARE_HOTEL_ID_PAGES,pages.get());*//*
        //根据酒店列表获取房型列表然后进行效验
   *//*    compareHotels.values().forEach(e->{
            SwitchBasicRoomType switchRoomType=new SwitchBasicRoomType();
            //母酒店id
            switchRoomType.setHotelId(e.getSwitchHotelId());
            List<SwitchBasicRoomType> switchRoomTypes=switchBasicRoomTypeMapper.select(switchRoomType);
            //获取美团的房型列表
            MtHotelRoom mtHotelRoom=new MtHotelRoom();
            mtHotelRoom.setMtHotelId(e.getMtHotelId());
            List<MtHotelRoom> mtHotelRooms=mtHotelRoomMapper.select(mtHotelRoom);
            compareHotelRoomsByList(switchRoomTypes,mtHotelRooms);
        });*//*

        //测试数据
   *//*     SwitchBasicRoomType switchRoomType=new SwitchBasicRoomType();
        switchRoomType.setHotelId(485160);
        List<SwitchBasicRoomType> switchRoomTypes=switchBasicRoomTypeMapper.select(switchRoomType);
        //获取美团的房型列表
        MtHotelRoom mtHotelRoom=new MtHotelRoom();
        mtHotelRoom.setMtHotelId("101715118");
        List<MtHotelRoom> mtHotelRooms=mtHotelRoomMapper.select(mtHotelRoom);
        compareHotelRoomsByList(switchRoomTypes,mtHotelRooms);*//*
        return new Result<>("对比任务完成");
    }*/
    /**
     * @author: lmf
     * @date: 2020/8/13 15:07
     * 优化房型匹配匹配问题
     */
    @Override
    public Result<Object> adjust(){
        SwitchBasicRoomType switchRoomType=new SwitchBasicRoomType();
        //母酒店id
        switchRoomType.setMasterHotelId(1318680);
        List<SwitchBasicRoomType> switchRoomTypes=switchBasicRoomTypeMapper.select(switchRoomType);
        //获取美团的房型列表
        MtHotelRoom mtHotelRoom=new MtHotelRoom();
        mtHotelRoom.setMtHotelId("2145983");
        List<MtHotelRoom> mtHotelRooms=mtHotelRoomMapper.select(mtHotelRoom);
        /*int result=compareHotelRoomsByList(switchRoomTypes,mtHotelRooms);*/
       /* log.info("============result的值为{}",result);*/
        return new Result<>("=====================效验完成=========");
    }

    /**
     * 效验生成子酒店的房型列表
     */
    @Override
    public Result<Object>  getCanCreateSubHotel(){
        //1.获取已经创建的子酒店列表
        List<SwitchCreateSubHotel> switchCreateSubHotelEntities=switchCreateSubHotelMapper.getNoCompareHotel();
        for(SwitchCreateSubHotel switchCreateSubHotel:switchCreateSubHotelEntities){
            //获取效验表数据
            CompareHotel compareHotel=compareHotelMapper.selectMtHotelId(switchCreateSubHotel.getMasterHotelId());
            if(ObjectUtils.isEmpty(compareHotel)){
                log.info("===========switchCreateSubHotel的值为{}",switchCreateSubHotel.toString());
                continue;
            }
            //携程的房型列表
            List<SwitchBasicRoomType> switchRoomTypes=compareHotelBasicRoomMapper.getNoMatchSwitchRoom(switchCreateSubHotel.getMasterHotelId());

            //获取美团的房型列表
            String mtHotelId=compareHotel.getMtHotelId();
            String key="compare_meituan_hotel_room_"+mtHotelId;
            List<MtRoomInfoDto> list=new ArrayList<>();
            if(redisService.exists(key)){
                String json= (String) redisService.get(key);
                list= JacksonUtil.jsonToList(json,MtRoomInfoDto.class);
            }else{
                //判断美团的房型id是否发生变动
                String url = CommonUrlConstants.MEITUAN_HOST + CompareRequestUrlEnums.GET_MEI_TUAN_HOTEL_ROOM_LIST.getUrl();
                Map<String, Object> params=new HashMap<>();
                params.put("mtHotelId",mtHotelId);
                try {
                    Result<List<MtRoomInfoDto>> result = compareRestTempaleUtilsService.sendPostToMeiTuanHotelRoomList(url, params);
                    if (result.getCode() == CommonConstants.SUCCESS) {
                        log.info("=====请求获取效验房型控制器成功,美团的房型id为:{}=======", result.getData());
                        list=result.getData();
                        if(!ObjectUtils.isEmpty(list)&&list.size()>0){
                            redisService.set(key, JSON.toJSONString(list),(long)43200);
                        }
                    } else {
                        log.info("========get mt-hotel_id error");
                        continue;
                    }
                } catch (Exception e) {
                    log.info("========get mt-hotel_id error");
                    continue;
                }
            }
            if(ObjectUtils.isEmpty(list)||list.size()<1){
               continue;
            }
            //List<MtHotelRoom> mtHotelRooms=compareHotelBasicRoomMapper.getNoMatchMtRoom(compareHotel.getMtHotelId());
            compareHotelRoomsByList(switchRoomTypes,list,mtHotelId);
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
           /* if(result>0){
                switchCreateSubHotelMapper.updateByMasterHotelId(switchCreateSubHotel.getMasterHotelId());
            }*/
        }
     /*   //携程的房型列表
        List<SwitchBasicRoomType> switchRoomTypes=compareHotelBasicRoomMapper.getNoMatchSwitchRoom(1736604);
        //获取美团的房型列表
        List<MtHotelRoom> mtHotelRooms=compareHotelBasicRoomMapper.getNoMatchMtRoom("4303514");*/
        /*int result=compareHotelRoomsByList(switchRoomTypes,mtHotelRooms);
        if(result>0){
            switchCreateSubHotelMapper.updateByMasterHotelId(switchCreateSubHotel.getMasterHotelId());
        }*/
        return new Result<>("对比成功");
    }


    /**
     * 用来初始化数据
     */
    @Override
    public void initData(){
        if(redisService.exists(CommonConstants.COMPARE_HOTEL_ID)){
            compareHotels= (Map<String, CompareHotel>) redisService.get(CommonConstants.COMPARE_HOTEL_ID);
        }
        List<CompareHotel> compareHotelList=compareHotelMapper.getCompareHotel();
        for(CompareHotel compareHotel:compareHotelList){
            if(ObjectUtils.isEmpty(compareHotel)){
                continue;
            }
            String id=compareHotel.getSwitchHotelId()+compareHotel.getMtHotelId();
            if(compareHotels.containsKey(id)){
                compareHotels.put(id,compareHotel);
            }else{
                compareHotels.put(id,compareHotel);
            }
        }
        redisService.set(CommonConstants.COMPARE_HOTEL_ID,compareHotels);
    }

    /**
     * 开启多线程 房型效验
     */
    @Override
    @Transactional
    public Result<Object> compareHotelRoom(){
        //1.获取效验通过的酒店列表
        //key:携程+美团id value:效验后的房型信息
        if(redisService.exists(CommonConstants.COMPARE_HOTEL_ID)){
            compareHotels= (Map<String, CompareHotel>) redisService.get(CommonConstants.COMPARE_HOTEL_ID);
        }
        //key:从零开始 valye:携程+美团id
        if(redisService.exists(CommonConstants.COMPARE_HOTEL_ID_NUM)){
            isCompareNumMap= (Map<Integer, String>) redisService.get(CommonConstants.COMPARE_HOTEL_ID_NUM);
        }

        if(MapUtils.isEmpty(isCompareNumMap)|| MapUtils.isEmpty(compareHotels)){
            return new Result<>("暂无酒店数据可效验");
        }


        //2.保存每一页的执行位置,如果中断定时任务，下一次接的继续跑
        //key:页数 value:执行的位置
        Map<Integer,Integer> pageMap;
        if(redisService.exists(CommonConstants.COMPARE_HOTEL_ID_PAGE_MAP)){
            pageMap= (Map<Integer, Integer>) redisService.get(CommonConstants.COMPARE_HOTEL_ID_PAGE_MAP);
        }else{
            pageMap=new HashMap<>();
        }
        //获取酒店长度来计算需要开启的线程数
        double size=(double) isCompareNumMap.size()/400;
        int total= (int) Math.ceil(size);

        int ThreadNum=(total>10)?10:total;

        //获取执行的次数
        //必须每次开启线程的酒店数量全部跑完才会加+1,如果定时任务关掉，下一次进来会跑没跑完的数据先跑
        int num=0;
        if(redisService.exists(CommonConstants.COMPARE_HOTEL_ID_NUMS)){
            num= (int) redisService.get(CommonConstants.COMPARE_HOTEL_ID_NUMS);
        }
        //3.创建十个线程
        List<Future<Integer>> threads=new ArrayList<>();
        for(int i=1;i<=ThreadNum;i++){
            //获取当前页
            int page=i+(num*10);
            //判断当前页的数据是否跑完
            if(pageMap.containsKey(page)){
                //判断当前页是否已经完全，效验完
                int index=pageMap.get(page);
                //说明还没有效验完，继续效验
                if(index<(page*400-1)){
                    log.info("=====当前页数为{}=====",page);
                    threads.add(executor.submit(new RoomCallable("线程名称为thread"+i,1000,page,index,compareHotels,isCompareNumMap)));
                }else{
                    log.info("=======当前{}页的数据已经效验完",page);
                }
            }else{
                threads.add(executor.submit(new RoomCallable("线程名称为thread"+i, 1000, page,(page-1)*400,compareHotels,isCompareNumMap)));
            }
        }
        boolean result=false;
        //遍历任务结果
        for(Future<Integer> future:threads){
            try {
                if(future.get()==1){
                    result=true;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }finally {
                executor.shutdown();
            }
        }
        if(result){
            redisService.set(CommonConstants.COMPARE_HOTEL_ID_NUMS,num+1);
        }
        System.out.println("所有的统计任务执行完成:" + sdf.format(new Date()));
        return new Result<>("此次效验房型效验成功");
    }

    /**
     * 内部类用来处理房型信息
     */
    class RoomCallable implements Callable<Integer> {
        String threaName;

        int page;

        int index;

        int runTime;
        Map<String, CompareHotel> map;
        Map<Integer, String> keysMap;

        RoomCallable(String threaName, int runTime, int page, int index, Map<String, CompareHotel> map, Map<Integer, String> keysMap) {
            this.threaName = threaName;
            this.page = page;
            this.index = index;
            this.runTime=runTime;
            this.map=map;
            this.keysMap=keysMap;
        }

        @Override
        public Integer call() throws Exception {
            int current=0;
            try{
                for(;index<400*page;index++){
                    //先获取value:携程酒店id+美团酒店id
                    String key=this.keysMap.get(index);
                    CompareHotel compareHotel=compareHotels.get(key);
                    log.info("=====获取的酒店信息为========为{}",compareHotel);
                    if(ObjectUtils.isEmpty(compareHotel)){
                        return 0;
                    }
                    SwitchBasicRoomType switchRoomType=new SwitchBasicRoomType();
                    //母酒店id
                    switchRoomType.setMasterHotelId(compareHotel.getSwitchHotelId());
                    List<SwitchBasicRoomType> switchRoomTypes=switchBasicRoomTypeMapper.select(switchRoomType);
                    //获取美团的房型列表
                    MtHotelRoom mtHotelRoom=new MtHotelRoom();
                    mtHotelRoom.setMtHotelId(compareHotel.getMtHotelId());
                    List<MtHotelRoom> mtHotelRooms=mtHotelRoomMapper.select(mtHotelRoom);
                   /* int result=compareHotelRoomsByList(switchRoomTypes,mtHotelRooms);
                    if(result>0){
                        current=index;
                        pageMap.put(page,index);
                        redisService.set(CommonConstants.COMPARE_HOTEL_ID_PAGE_MAP,pageMap);
                    }*/
                }
                Thread.sleep(runTime);
            }catch (Exception e){
                return 0;
            }
            if(current==(400*page-1)){
                return 1;
            }else{
                return 0;
            }
        }
    }

    /**
     * 效验酒店房型信息
     * 匹配规则:
     * 名称 （有无楼层 有无窗暂时不需要匹配，到时候是根据美团这边来设置）
     */
    public  int   compareHotelRoomsByList(List<SwitchBasicRoomType> switchRoomTypes, List<MtRoomInfoDto> mtRoomInfoDtos, String mtHotelId){
        if(ObjectUtils.isEmpty(mtRoomInfoDtos)||mtRoomInfoDtos.size()< 1){
            log.info("===========暂无可比数据123================");
            return 0;
        }
        //遍历房型列表
        switchName:for (SwitchBasicRoomType switchRoomType:switchRoomTypes){
            //攜程的房型名稱
            String roomName=switchRoomType.getBasicRoomName().replaceAll(" ","").replaceAll("3","三").replaceAll("4","四");
            String remark="";

            for (MtRoomInfoDto mtRoomInfoDto:mtRoomInfoDtos){
                //美团房型名称
                String mtRoomName=mtRoomInfoDto.getRoomName().replaceAll(" ","").replaceAll("3","三").replaceAll("4","四");
                if(roomName.equals(mtRoomName)){
                    log.info("======携程的房型名称为{}美团的房型名称为{}======",roomName,mtRoomName);
                    //1.判断该房型是否已经有匹配对象，存在就不能重复匹配
                    int isHave=compareHotelBasicRoomMapper.selectHotelIdAndRoomId(switchRoomType.getHotelId(), String.valueOf(switchRoomType.getMasterBasicRoomId()));
                    if(isHave>0){
                        continue switchName;
                    }
                    //2.先判断表里是否存在，如果存在就不保存了
                    int result=compareHotelBasicRoomMapper.selectMtHotelIdAndMtHotelRoomIdAndHotelIdAndRoomId(mtHotelId,String.valueOf(mtRoomInfoDto.getRoomId()),switchRoomType.getHotelId(),String.valueOf(switchRoomType.getMasterBasicRoomId()));
                    if(result>0){
                        log.info("============房型名称为{}美团的房型名称为{}已经匹配成功入效验库了======",roomName,mtRoomName);
                        continue switchName;
                    }
                    CompareHotelBasicRoom compareHotelRoom=new CompareHotelBasicRoom();
                    //携程酒店表id
                    // compareHotelRoom.setSwitchId(switchRoomType.getId());
                    //携程房型表id
                    //compareHotelRoom.setSwitchRoomId(switchRoomType.getId());
                    //携程子酒店id
                    compareHotelRoom.setSwitchHotelId(switchRoomType.getHotelId());
                    //携程房型id
                    log.info("==========携程母物理房型的switch_hotel_room_id为{}==================",switchRoomType.getMasterBasicRoomId());
                    compareHotelRoom.setSwitchHotelRoomId(String.valueOf(switchRoomType.getMasterBasicRoomId()));
                    compareHotelRoom.setCreateTime(new Date());
                    compareHotelRoom.setModifyTime(new Date());
                    synchronized (CompareHotelRoomServiceImpl.class){
                        compareHotelRoom.setId(StringUtil.getUUID());
                    }
                    //携程母酒店id
                    compareHotelRoom.setSwitchMasterHotelId(switchRoomType.getMasterHotelId());
                    //美团酒店表id
                    // compareHotelRoom.setMtTd(mtHotelRoom.getId());
                    //美团酒店id
                    compareHotelRoom.setMtHotelId(mtHotelId);
                    //美团房型表id
                    // compareHotelRoom.setMtRoomId(mtHotelRoom.getId());
                    //美团房型id
                    compareHotelRoom.setMtHotelRoomId(String.valueOf(mtRoomInfoDto.getRoomId()));
                    compareHotelRoom.setMtRoomName(mtRoomInfoDto.getRoomName());
                    compareHotelRoom.setSwitchRoomName(switchRoomType.getBasicRoomName());
                    compareHotelRoom.setIsCompare(1);
                    compareHotelRoom.setCreateState(0);
                    compareHotelRoom.setState(0);
                    compareHotelRoom.setRemark(remark);
                    compareHotelBasicRoomMapper.insert(compareHotelRoom);
                }

            }
        }
        return 1;
    }
    /**
     * 效验酒店房型信息
     * 匹配规则:
     * 名称 有无楼层 有无窗
     */
    public int compareHotelRoomsByList2(List<SwitchRoomType> switchRoomTypes, List<MtHotelRoom> mtHotelRooms){
        if(switchRoomTypes.size()<1||mtHotelRooms.size()<1){
            log.info("暂无数据可比");
            return 0;
        }

        //构造表单保存数据
        List<CompareHotelRoom> compareHotelRooms=new ArrayList<>();
        //通过效验的数据加入到缓存中，提供给床型效验使用
        Map<String, CompareHotelRoom> efficagy=new HashMap<>();

        //用来判断数据是否已经效验过
        Map<String,Integer> hasEfficagy=new HashMap<>();

        //判断redis是否已经有效验通过的房型数据
        if(redisService.exists(CommonConstants.COMPARE_ROOM_ID)){
            efficagy= (Map<String, CompareHotelRoom>) redisService.get(CommonConstants.COMPARE_ROOM_ID);
        }


        //判断redis是否有效验数据
        if(redisService.exists(CommonConstants.SWITCH_MEITUAN_ROOM_ID)){
            hasEfficagy= (Map<String, Integer>) redisService.get(CommonConstants.SWITCH_MEITUAN_ROOM_ID);
        }

        //遍历房型列表
        for (SwitchRoomType switchRoomType:switchRoomTypes){
            String roomName=switchRoomType.getRootTypeName();
            //默认未校验
            int isCompare = 0;
            String remark="";
            String key="";
            //上面这层先做判空
            if(StringUtils.isEmpty(roomName)||roomName.length()<1){
                log.info("携程的房型名称为空");
                continue;
            }

            switchLab:for (MtHotelRoom mtHotelRoom:mtHotelRooms){
                //美团房型名称
                String mtRoomName=mtHotelRoom.getMtRoomName();
                //携程母物理房型id+美团房型id 作为唯一key
                key=switchRoomType.getMasterBasicRoomTypeId()+mtHotelRoom.getMtRoomId();
                //如果该组合效验过无需重复效验
                if(hasEfficagy.containsKey(key)){
                    log.info("已经效验过，我就跳过了");
                    continue switchLab;
                }
                //匹配房型名称
//                if(StringUtils.isEmpty(roomName)||roomName.length()<1){
//                    log.info("携程的房型名称为空");
//                    continue;
//                }
                if(StringUtils.isEmpty(mtRoomName)||mtRoomName.length()<1){
                    log.info("美团的房型名称为空");
                    continue;
                }


                CompareHotelRoom compareHotelRoom=new CompareHotelRoom();
                //携程酒店表id
                // compareHotelRoom.setSwitchId(switchRoomType.getId());
                //携程房型表id
                //compareHotelRoom.setSwitchRoomId(switchRoomType.getId());
                //携程酒店id
                compareHotelRoom.setSwitchHotelId(switchRoomType.getHotelId());
                //携程房型id
                log.info("switch_hotel_room_id{}",switchRoomType.getRoomTypeId());
                compareHotelRoom.setSwitchHotelRoomId(String.valueOf(switchRoomType.getRoomTypeId()));
                compareHotelRoom.setCreateTime(new Date());
                compareHotelRoom.setModifyTime(new Date());
                compareHotelRoom.setId(StringUtil.getUUID());
                //美团酒店表id
                // compareHotelRoom.setMtTd(mtHotelRoom.getId());
                //美团酒店id
                compareHotelRoom.setMtHotelId(mtHotelRoom.getMtHotelId());
                //美团房型表id
               // compareHotelRoom.setMtRoomId(mtHotelRoom.getId());
                //美团房型id
                compareHotelRoom.setMtHotelRoomId(mtHotelRoom.getMtRoomId());


                boolean similar= CompareUtil.isSimilAr(roomName,mtRoomName);
                //已效验但未通过
                if(!similar){
                    remark="携程和美团房型名称不匹配";
                    log.info("携程{}美团{}房型效验但未通过",roomName,mtRoomName);
                    isCompare=2;
                }else{
                    int mtRoomWindow=mtHotelRoom.getMtWindow();
                    int swRoomWindow=switchRoomType.getHasWindow();
                    if(ObjectUtils.isEmpty(mtRoomWindow)|| ObjectUtils.isEmpty(swRoomWindow)){
                        log.info("美团和携程存在有无窗为空的情况");
                        continue;
                    }
                    //有无窗效验
                    boolean isSimilar=CompareUtil.isSimilarByWindow(mtRoomWindow,swRoomWindow);
                    if(!isSimilar){
                        remark="携程和美团房型名称一致，有无窗不匹配";
                        log.info("携程{}美团{}有无窗效验但未通过",roomName,mtRoomName);
                        isCompare=2;
                    }else{
                        String mtFloor=mtHotelRoom.getMtFloor();
                        String swFloor=switchRoomType.getFloorRange();
                        if(ObjectUtils.isEmpty(mtFloor)|| ObjectUtils.isEmpty(swFloor)){
                            log.info("美团和携程存在楼层为空的情况");
                            continue;
                        }
                        //楼层效验
                        boolean isSimilarByFloor=CompareUtil.isSimilarByFloor(mtFloor,swFloor) ;
                        log.info("携程楼层{}美团楼层{}",swFloor,mtFloor);
                        if(!isSimilarByFloor){
                            remark="携程和美团房型名称一致，有无窗一致,楼层不匹配";
                            log.info("携程{}美团{}有无楼层但未通过",roomName,mtRoomName);
                            isCompare=2;
                        }else {
                            isCompare = 1;
                        }
                    }
                }
                compareHotelRoom.setIsCompare(isCompare);
                compareHotelRoom.setRemark(remark);
                compareHotelRooms.add(compareHotelRoom);

                //如果有匹配成功的就过滤掉
                if(isCompare==1){
                    log.info("携程{}----美团{}匹配成功",roomName,mtRoomName);
                    mtHotelRooms.remove(switchRoomType);
                    //判断之前是否存在效验过的数据,存在无需新增
                    if(!efficagy.containsKey(key)){
                        efficagy.put(key,compareHotelRoom);
                    }
                }

                //判断是否添加到效验集合
                if(!hasEfficagy.containsKey(key)){
                    hasEfficagy.put(key,isCompare);
                }

            }
        }
        int result=0;
        //保存入库
        if(compareHotelRooms.size()>0){
            result= compareHotelRoomMapper.insertList(compareHotelRooms);
        }
        //加入缓存
        if(result>0){

            if(!MapUtil.isEmpty(efficagy)){
                redisService.set(CommonConstants.COMPARE_ROOM_ID,efficagy);
            }

          /*  if(!MapUtil.isEmpty(hasEfficagy)){
                redisService.set(CommonConstants.SWITCH_MEITUAN_ROOM_ID,hasEfficagy);
            }*/

        }
        return result;
    }

    /**
     * 获取效验后的房型列表
     * @return
     */
    @Override
    public Result<Object> getCompareHotelRoomList() {
        List<CompareHotelRoom> compareHotelRooms=compareHotelRoomMapper.selectAll();
        return new Result<>(compareHotelRooms);
    }

    /**
     * 根据子物理房型id进行验证
     * @return
     */
    @Override
    public Result<Object> compareHotelRoomBySub() {
        log.info("校验房型");
        Map<String, CompareHotel> compareHotels= (Map<String, CompareHotel>) redisService.get(CommonConstants.COMPARE_HOTEL_ID);
        if(ObjectUtils.isEmpty(compareHotels)){
            return new Result<>("暂无可对比数据");
        }
        compareHotels.values().forEach(e->{
            SwitchRoomType switchRoomType=new SwitchRoomType();
            switchRoomType.setMasterHotelId(e.getSwitchHotelId());
            List<SwitchRoomType> switchRoomTypes=switchRoomTypeMapper.select(switchRoomType);
            //获取美团的房型列表
            MtHotelRoom mtHotelRoom=new MtHotelRoom();
            mtHotelRoom.setMtHotelId(e.getMtHotelId());
            List<MtHotelRoom> mtHotelRooms=mtHotelRoomMapper.select(mtHotelRoom);
            compareHotelRoomsByList2(switchRoomTypes,mtHotelRooms);
        });
        return new Result<>("对比任务完成");
    }

    /**
     * 根据母酒店id + 子酒店id 获取美团id
     * @param masterHotelId
     * @param roomId
     * @return
     */
    @Override
    public Result<MtHotelRoomVo> getCompareHotelInfo(Integer masterHotelId, Integer roomId) {
        MtHotelRoomVo mtHotelRoomvo= compareHotelBasicRoomMapper.getCompareHotelInfo(masterHotelId,roomId);
        mtHotelRoomvo=this.compareHotelRoomByInterface(mtHotelRoomvo,masterHotelId,roomId);
        return new Result<>(mtHotelRoomvo);
    }
    /**
     * @author: lmf
     * @date: 2020/9/16 11:39
     * 获取已匹配房型列表
     */
    @Override
    public Result<Object> getRoomList(GetRoomListVO getRoomListVO) {
        PageHelper.startPage(getRoomListVO.getPageCode(), getRoomListVO.getPageSize());
        List<CompareHotelRoomVo> compareHotelListList = compareHotelBasicRoomMapper.getCompareRoomList(getRoomListVO);
        PageInfo<CompareHotelRoomVo> pageInfo = new PageInfo<>(compareHotelListList);
        return new Result<>(pageInfo);
    }
    /**
     * @author: lmf
     * @date: 2020/9/16 14:34
     * 获取未效验的房型列表
     */
    @Override
    public Result<Object> getNoCompareRoomList(GetRoomListVO getRoomListVO) {
        PageHelper.startPage(getRoomListVO.getPageCode(), getRoomListVO.getPageSize());
        List<CompareHotelRoomVo> compareHotelListList = compareHotelBasicRoomMapper.getNoCompareRoomList(getRoomListVO);
        PageInfo<CompareHotelRoomVo> pageInfo = new PageInfo<>(compareHotelListList);
        return new Result<>(pageInfo);
    }
    /**
     * @author: lmf
     * @date: 2020/9/16 15:04
     * 获取美团未效验的房型列表
     */
    @Override
    public Result<Object> getMtNoCompareList(Integer masterHotelId) {
        List<CompareHotelRoomVo> compareHotelListList = compareHotelBasicRoomMapper.getMtNoCompareList(masterHotelId);
        return new Result<>(compareHotelListList);
    }
    /**
     * @author: lmf
     * @date: 2020/9/16 20:44
     * 添加入匹配库
     */
    @Override
    public Result<Object> matchSuccess(CompareHotelRoomVo compareHotelRoomVo) {
        CompareHotelBasicRoom compareHotelRoom=new CompareHotelBasicRoom();
        compareHotelRoom.setId(StringUtil.getUUID());
        compareHotelRoom.setSwitchHotelId(compareHotelRoomVo.getHotelId());
        compareHotelRoom.setSwitchHotelRoomId(String.valueOf(compareHotelRoomVo.getRoomId()));
        compareHotelRoom.setSwitchMasterHotelId(compareHotelRoomVo.getMasterHotelId());
        compareHotelRoom.setMtRoomName(compareHotelRoomVo.getMtRoomName());
        compareHotelRoom.setSwitchRoomName(compareHotelRoomVo.getRoomName());
        compareHotelRoom.setCreateTime(new Date());
        compareHotelRoom.setIsCompare(1);
        compareHotelRoom.setModifyTime(new Date());
        compareHotelRoom.setMtHotelId(String.valueOf(compareHotelRoomVo.getMtHotelId()));
        compareHotelRoom.setMtHotelRoomId(String.valueOf(compareHotelRoomVo.getMtRoomId()));
        compareHotelRoom.setRemark("人工匹配");
        int result=compareHotelBasicRoomMapper.insert(compareHotelRoom);
        if(result>0){
            return new Result<>();
        }else{
            return new Result<>("保存失败");
        }
    }
    /***
     * @Author: lmf
     * @Date: 2020/9/28
     * 通过sql语句进行房型效验 100%效验
     */
    @Override
    @Transactional
    public Result<Object> compareHotelBySql() {
        new compareHotelRoomThread().run();
        return new Result<>("匹配完成");
    }

    class compareHotelRoomThread implements Runnable{

        @Override
        public void run() {
            List<CompareHotelRoomBySql> compareHotelRoomBySqlList=compareHotelBasicRoomMapper.getCompareHotelRoomListAndTen();
            CompareHotelBasicRoom compareHotelBasicRoom;
            tab:for(CompareHotelRoomBySql compareHotelRoomBySql:compareHotelRoomBySqlList){
                log.info("=============对比完成，开始封装数据为{}",compareHotelRoomBySql.toString());
                compareHotelRoomBySql.setId(StringUtil.getUUID());
                compareHotelRoomBySql.setGenre(1);
                //先判断一下是否存在数据
                synchronized (this){
                   compareHotelBasicRoom=compareHotelBasicRoomMapper.selectByRoomIdAndMtRoomId(compareHotelRoomBySql.getMtHotelId(),compareHotelRoomBySql.getMtRoomId(),compareHotelRoomBySql.getHotelId(),compareHotelRoomBySql.getMasterBasicRoomId());
                }
                if(!ObjectUtils.isEmpty(compareHotelBasicRoom)){
                    log.info("================已经存在无需重复插入100%=====================");
                    //删除重复数据
                    continue tab;
                }
                compareHotelBasicRoom=new CompareHotelBasicRoom();
                compareHotelBasicRoom.setCreateTime(new Date());
                compareHotelBasicRoom.setId(StringUtil.getUUID());
                compareHotelBasicRoom.setIsCompare(1);
                compareHotelBasicRoom.setModifyTime(new Date());
                compareHotelBasicRoom.setMtHotelId(String.valueOf(compareHotelRoomBySql.getMtHotelId()));
                compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(compareHotelRoomBySql.getMtRoomId()));
                compareHotelBasicRoom.setMtRoomName(compareHotelRoomBySql.getMtRoomName());
                compareHotelBasicRoom.setSwitchRoomName(compareHotelRoomBySql.getBasicRoomName());
                compareHotelBasicRoom.setRemark("");
                compareHotelBasicRoom.setState(0);
                compareHotelBasicRoom.setSwitchHotelId(compareHotelRoomBySql.getHotelId());
                compareHotelBasicRoom.setSwitchMasterHotelId(compareHotelRoomBySql.getMasterHotelId());
                compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(compareHotelRoomBySql.getMasterBasicRoomId()));
               compareHotelBasicRoomMapper.insert(compareHotelBasicRoom);
            }
            log.info("==============已经进行百分百匹配完成，休息60s 进行规则过滤=======================");
            try {
                Thread.sleep(6000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            compareHotelRoomBySqlList=compareHotelBasicRoomMapper.getCompareHotelRoomList();
            tab:for(CompareHotelRoomBySql compareHotelRoomBySql:compareHotelRoomBySqlList){
                log.info("=============对比完成，开始封装数据为{}",compareHotelRoomBySql.toString());
                compareHotelRoomBySql.setId(StringUtil.getUUID());
                compareHotelRoomBySql.setGenre(1);
                //先判断一下是否存在数据
                synchronized (this){
                    compareHotelBasicRoom=compareHotelBasicRoomMapper.selectByRoomIdAndMtRoomId(compareHotelRoomBySql.getMtHotelId(),compareHotelRoomBySql.getMtRoomId(),compareHotelRoomBySql.getHotelId(),compareHotelRoomBySql.getMasterBasicRoomId());
                }
                if(!ObjectUtils.isEmpty(compareHotelBasicRoom)){
                    log.info("================已经存在无需重复插入过滤【人 间 房】=====================");
                    //删除重复数据
                    continue tab;
                }
                compareHotelBasicRoom=new CompareHotelBasicRoom();
                compareHotelBasicRoom.setCreateTime(new Date());
                compareHotelBasicRoom.setId(StringUtil.getUUID());
                compareHotelBasicRoom.setIsCompare(2);
                compareHotelBasicRoom.setModifyTime(new Date());
                compareHotelBasicRoom.setMtHotelId(String.valueOf(compareHotelRoomBySql.getMtHotelId()));
                compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(compareHotelRoomBySql.getMtRoomId()));
                compareHotelBasicRoom.setMtRoomName(compareHotelRoomBySql.getMtRoomName());
                compareHotelBasicRoom.setSwitchRoomName(compareHotelRoomBySql.getBasicRoomName());
                compareHotelBasicRoom.setRemark("通过规则过滤[人 间 房]进行匹配");
                compareHotelBasicRoom.setState(0);
                compareHotelBasicRoom.setSwitchHotelId(compareHotelRoomBySql.getHotelId());
                compareHotelBasicRoom.setSwitchMasterHotelId(compareHotelRoomBySql.getMasterHotelId());
                compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(compareHotelRoomBySql.getMasterBasicRoomId()));
                compareHotelBasicRoomMapper.insert(compareHotelBasicRoom);
            }
        }
    }

    /***
     * 根据效验房型根据酒店id
     * @param mtHotelId
     * @return
     */
    @Override
    public Result<Object> compareHotelRoomByHotelIdSql(Integer mtHotelId) {
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.submit(new CompareHotelRoomByHotelTherad(mtHotelId));
        executorService.shutdown();
        return new Result<>();
    }

    class CompareHotelRoomByHotelTherad implements Runnable{
        private Integer mtHotelId;
        public CompareHotelRoomByHotelTherad(Integer mtHotelId) {
            this.mtHotelId = mtHotelId;
        }

        @Override
        public void run() {
            String url = CommonUrlConstants.MEITUAN_HOST + CompareRequestUrlEnums.GET_MEI_TUAN_HOTEL_ROOM_REUTRN_LIST.getUrl();
            Map<String, Object> params=new HashMap<>();
            params.put("hotelId",mtHotelId.toString());
            List<MtHotelRealRoomVo> list=new ArrayList<>();
            try {
                Result<List<MtHotelRealRoomVo>> result = compareRestTempaleUtilsService.sendPostToMeiTuanHotelRoomReturnList(url, params);
                if (result.getCode() == CommonConstants.SUCCESS) {
                    log.info("=====请求获取效验房型控制器成功,美团的房型数据为{}=======", result.getData());
                    list=result.getData();
                }
            } catch (Exception e) {
                log.info("===============发生异常====================");
            }
            Integer siwtchHotelId=compareHotelMapper.getCompareHotelId(mtHotelId);
            if(!ObjectUtils.isEmpty(siwtchHotelId)){
                SwitchBasicRoomType switchRoomType=new SwitchBasicRoomType();
                //母酒店id
                switchRoomType.setMasterHotelId(siwtchHotelId);
                List<SwitchBasicRoomType> switchRoomTypes=switchBasicRoomTypeMapper.select(switchRoomType);
                log.info("=========携程的房型列表为{}=========",switchRoomTypes.toString());
                if(!ObjectUtils.isEmpty(list)&&list.size()>0){
                    CompareHotelBasicRoom compareHotelBasicRoom;
                    tab:for(MtHotelRealRoomVo mtHotelRealRoomVo:list){
                        StringBuilder mtRoomName= new StringBuilder(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName().replaceAll(" ", "").replaceAll("\\(", "").replaceAll("\\)", "").replaceAll("3", "三").replaceAll("4", "四"));
                        log.info("==========遍历开始数据为{}====",mtHotelRealRoomVo.getRealRoomBaseInfo().toString());
                        String basicRoomName="";
                        switchTab:for(SwitchBasicRoomType switchBasicRoomType:switchRoomTypes){
                            String siwtchRoomName=switchBasicRoomType.getBasicRoomName().replaceAll(" ","").replaceAll("\\(","").replaceAll("\\)","").replaceAll("3","三").replaceAll("4","四");
                            if(mtRoomName.toString().equals(siwtchRoomName)){
                                basicRoomName=switchBasicRoomType.getBasicRoomName();
                                Integer masterBasicRoomId=switchBasicRoomType.getMasterBasicRoomId();
                                //如果是无窗
                                if(mtHotelRealRoomVo.getRealRoomBaseInfo().getWindow()==2){
                                    mtRoomName.append("无窗");
                                    for(SwitchBasicRoomType switchBasicRoomType1:switchRoomTypes){
                                        String roomName=switchBasicRoomType1.getBasicRoomName().replaceAll(" ","").replaceAll("\\(","").replaceAll("\\)","").replaceAll("3","三").replaceAll("4","四");
                                        if(mtRoomName.toString().equals(roomName)){
                                            basicRoomName=switchBasicRoomType1.getBasicRoomName();
                                            log.info("=========美团的物理房型为无窗，找到携程有无窗房型进行映射=================");
                                            masterBasicRoomId=switchBasicRoomType1.getMasterBasicRoomId();
                                            break ;
                                        }

                                    }
                                }
                                log.info("=======百分百一样=======");
                                CompareHotelBasicRoom compareHotelBasicRoomold=compareHotelBasicRoomMapper.getHotelRoomInfo(switchBasicRoomType.getMasterHotelId(), masterBasicRoomId);
                                //没有效验数据，就直接插入
                                if(ObjectUtils.isEmpty(compareHotelBasicRoomold)){
                                    compareHotelBasicRoomold=compareHotelBasicRoomMapper.getHotelRoomInfoByMtHotelIdAndMtRoomId(mtHotelId, mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId());
                                    if(ObjectUtils.isEmpty(compareHotelBasicRoomold)){
                                        log.info("=======不存在=======");
                                        compareHotelBasicRoom=new CompareHotelBasicRoom();
                                        compareHotelBasicRoom.setCreateTime(new Date());
                                        compareHotelBasicRoom.setId(StringUtil.getUUID());
                                        compareHotelBasicRoom.setIsCompare(1);
                                        compareHotelBasicRoom.setModifyTime(new Date());
                                        compareHotelBasicRoom.setMtHotelId(String.valueOf(mtHotelId));
                                        compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId()));
                                        compareHotelBasicRoom.setMtRoomName(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName());
                                        compareHotelBasicRoom.setSwitchRoomName(basicRoomName);
                                        compareHotelBasicRoom.setRemark("");
                                        compareHotelBasicRoom.setState(0);
                                        compareHotelBasicRoom.setCreateState(0);
                                        compareHotelBasicRoom.setSwitchHotelId(switchBasicRoomType.getHotelId());
                                        compareHotelBasicRoom.setSwitchMasterHotelId(switchBasicRoomType.getMasterHotelId());
                                        compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(masterBasicRoomId));
                                        compareHotelBasicRoomMapper.insert(compareHotelBasicRoom);

                                    }else{
                                        //如果效验数据一样就跳过
                                        if(compareHotelBasicRoomold.getMtHotelRoomId().equals(String.valueOf(mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId()))){
                                            log.info("=============数据一致直接跳过===================");
                                            continue switchTab;
                                        }else{//出现房型id不一样就进行更新
                                            log.info("==================数据不一样的=========");
                                            compareHotelBasicRoom=new CompareHotelBasicRoom();
                                            compareHotelBasicRoom.setCreateTime(new Date());
                                            compareHotelBasicRoom.setModifyTime(new Date());
                                            compareHotelBasicRoom.setId(StringUtil.getUUID());
                                            compareHotelBasicRoom.setIsCompare(1);
                                            compareHotelBasicRoom.setModifyTime(new Date());
                                            compareHotelBasicRoom.setMtHotelId(String.valueOf(mtHotelId));
                                            compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId()));
                                            compareHotelBasicRoom.setMtRoomName(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName());
                                            compareHotelBasicRoom.setSwitchRoomName(switchBasicRoomType.getBasicRoomName());
                                            compareHotelBasicRoom.setRemark("");
                                            compareHotelBasicRoom.setState(0);
                                            compareHotelBasicRoom.setCreateState(0);
                                            compareHotelBasicRoom.setSwitchHotelId(switchBasicRoomType.getHotelId());
                                            compareHotelBasicRoom.setSwitchMasterHotelId(switchBasicRoomType.getMasterHotelId());
                                            compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(masterBasicRoomId));
                                            Example example=new Example(CompareHotelBasicRoom.class);
                                            Example.Criteria criteria=example.createCriteria();
                                            criteria.andEqualTo("switchHotelId",switchBasicRoomType.getHotelId());
                                            criteria.andEqualTo("switchHotelRoomId",masterBasicRoomId);
                                            compareHotelBasicRoomMapper.updateByExampleSelective(compareHotelBasicRoom,example);
                                        }
                                    }
                                }else{
                                    //如果效验数据一样就跳过
                                    if(compareHotelBasicRoomold.getMtHotelRoomId().equals(String.valueOf(mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId()))){
                                        log.info("=============数据一致直接跳过===================");
                                        continue switchTab;
                                    }else{//出现房型id不一样就进行更新
                                        log.info("==================数据不一样的=========");
                                        compareHotelBasicRoom=new CompareHotelBasicRoom();
                                        compareHotelBasicRoom.setCreateTime(new Date());
                                        compareHotelBasicRoom.setModifyTime(new Date());
                                        compareHotelBasicRoom.setId(StringUtil.getUUID());
                                        compareHotelBasicRoom.setIsCompare(1);
                                        compareHotelBasicRoom.setModifyTime(new Date());
                                        compareHotelBasicRoom.setMtHotelId(String.valueOf(mtHotelId));
                                        compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId()));
                                        compareHotelBasicRoom.setMtRoomName(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName());
                                        compareHotelBasicRoom.setSwitchRoomName(switchBasicRoomType.getBasicRoomName());
                                        compareHotelBasicRoom.setRemark("");
                                        compareHotelBasicRoom.setState(0);
                                        compareHotelBasicRoom.setCreateState(0);
                                        compareHotelBasicRoom.setSwitchHotelId(switchBasicRoomType.getHotelId());
                                        compareHotelBasicRoom.setSwitchMasterHotelId(switchBasicRoomType.getMasterHotelId());
                                        compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(masterBasicRoomId));
                                        Example example=new Example(CompareHotelBasicRoom.class);
                                        Example.Criteria criteria=example.createCriteria();
                                        criteria.andEqualTo("switchHotelId",switchBasicRoomType.getHotelId());
                                        criteria.andEqualTo("switchHotelRoomId",masterBasicRoomId);
                                        compareHotelBasicRoomMapper.updateByExampleSelective(compareHotelBasicRoom,example);
                                    }
                                }
                            }
                        }
                    }
                }
            }
 /*           String key=CommonConstants.SWITCH_MT_ONE_HOTEL_ROOMS_REDIS+mtHotelId.toString();
            Integer siwtchHotelId=compareHotelMapper.getCompareHotelId(mtHotelId);
            if(redisService.exists(key)){
                log.info("========走美团内容的接口进行取数据做对比===================");
                String json= (String) redisService.get(key);
                List<MtHotelRealRoomVo> list=GsonUtils.jsonToList(json,MtHotelRealRoomVo.class);
                if(!ObjectUtils.isEmpty(siwtchHotelId)){
                    SwitchBasicRoomType switchRoomType=new SwitchBasicRoomType();
                    //母酒店id
                    switchRoomType.setMasterHotelId(siwtchHotelId);
                    List<SwitchBasicRoomType> switchRoomTypes=switchBasicRoomTypeMapper.select(switchRoomType);
                    log.info("=========携程的房型列表为{}=========",switchRoomTypes.toString());
                    if(!ObjectUtils.isEmpty(list)&&list.size()>0){
                        CompareHotelBasicRoom compareHotelBasicRoom;
                        tab:for(MtHotelRealRoomVo mtHotelRealRoomVo:list){
                            StringBuilder mtRoomName= new StringBuilder(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName().replaceAll(" ", "").replaceAll("\\(", "").replaceAll("\\)", "").replaceAll("3", "三").replaceAll("4", "四"));
                            log.info("==========遍历开始数据为{}====",mtHotelRealRoomVo.getRealRoomBaseInfo().toString());
                            String basicRoomName="";
                           switchTab:for(SwitchBasicRoomType switchBasicRoomType:switchRoomTypes){
                                String siwtchRoomName=switchBasicRoomType.getBasicRoomName().replaceAll(" ","").replaceAll("\\(","").replaceAll("\\)","").replaceAll("3","三").replaceAll("4","四");
                                if(mtRoomName.toString().equals(siwtchRoomName)){
                                    basicRoomName=switchBasicRoomType.getBasicRoomName();
                                    Integer masterBasicRoomId=switchBasicRoomType.getMasterBasicRoomId();
                                    //如果是无窗
                                    if(mtHotelRealRoomVo.getRealRoomBaseInfo().getWindow()==2){
                                        mtRoomName.append("无窗");
                                        for(SwitchBasicRoomType switchBasicRoomType1:switchRoomTypes){
                                            String roomName=switchBasicRoomType1.getBasicRoomName().replaceAll(" ","").replaceAll("\\(","").replaceAll("\\)","").replaceAll("3","三").replaceAll("4","四");
                                            if(mtRoomName.toString().equals(roomName)){
                                                basicRoomName=switchBasicRoomType1.getBasicRoomName();
                                                log.info("=========美团的物理房型为无窗，找到携程有无窗房型进行映射=================");
                                                masterBasicRoomId=switchBasicRoomType1.getMasterBasicRoomId();
                                                break ;
                                            }

                                        }
                                    }
                                    log.info("=======百分百一样=======");
                                    CompareHotelBasicRoom compareHotelBasicRoomold=compareHotelBasicRoomMapper.getHotelRoomInfo(switchBasicRoomType.getMasterHotelId(), masterBasicRoomId);
                                    //没有效验数据，就直接插入
                                    if(ObjectUtils.isEmpty(compareHotelBasicRoomold)){
                                        compareHotelBasicRoomold=compareHotelBasicRoomMapper.getHotelRoomInfoByMtHotelIdAndMtRoomId(mtHotelId, mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId());
                                        if(ObjectUtils.isEmpty(compareHotelBasicRoomold)){
                                            log.info("=======不存在=======");
                                            compareHotelBasicRoom=new CompareHotelBasicRoom();
                                            compareHotelBasicRoom.setCreateTime(new Date());
                                            compareHotelBasicRoom.setId(StringUtil.getUUID());
                                            compareHotelBasicRoom.setIsCompare(1);
                                            compareHotelBasicRoom.setModifyTime(new Date());
                                            compareHotelBasicRoom.setMtHotelId(String.valueOf(mtHotelId));
                                            compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId()));
                                            compareHotelBasicRoom.setMtRoomName(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName());
                                            compareHotelBasicRoom.setSwitchRoomName(basicRoomName);
                                            compareHotelBasicRoom.setRemark("");
                                            compareHotelBasicRoom.setState(0);
                                            compareHotelBasicRoom.setCreateState(0);
                                            compareHotelBasicRoom.setSwitchHotelId(switchBasicRoomType.getHotelId());
                                            compareHotelBasicRoom.setSwitchMasterHotelId(switchBasicRoomType.getMasterHotelId());
                                            compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(masterBasicRoomId));
                                            compareHotelBasicRoomMapper.insert(compareHotelBasicRoom);

                                        }else{
                                            //如果效验数据一样就跳过
                                            if(compareHotelBasicRoomold.getMtHotelRoomId().equals(String.valueOf(mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId()))){
                                                log.info("=============数据一致直接跳过===================");
                                                continue switchTab;
                                            }else{//出现房型id不一样就进行更新
                                                log.info("==================数据不一样的=========");
                                                compareHotelBasicRoom=new CompareHotelBasicRoom();
                                                compareHotelBasicRoom.setCreateTime(new Date());
                                                compareHotelBasicRoom.setModifyTime(new Date());
                                                compareHotelBasicRoom.setId(StringUtil.getUUID());
                                                compareHotelBasicRoom.setIsCompare(1);
                                                compareHotelBasicRoom.setModifyTime(new Date());
                                                compareHotelBasicRoom.setMtHotelId(String.valueOf(mtHotelId));
                                                compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId()));
                                                compareHotelBasicRoom.setMtRoomName(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName());
                                                compareHotelBasicRoom.setSwitchRoomName(switchBasicRoomType.getBasicRoomName());
                                                compareHotelBasicRoom.setRemark("");
                                                compareHotelBasicRoom.setState(0);
                                                compareHotelBasicRoom.setCreateState(0);
                                                compareHotelBasicRoom.setSwitchHotelId(switchBasicRoomType.getHotelId());
                                                compareHotelBasicRoom.setSwitchMasterHotelId(switchBasicRoomType.getMasterHotelId());
                                                compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(masterBasicRoomId));
                                                Example example=new Example(CompareHotelBasicRoom.class);
                                                Example.Criteria criteria=example.createCriteria();
                                                criteria.andEqualTo("switchHotelId",switchBasicRoomType.getHotelId());
                                                criteria.andEqualTo("switchHotelRoomId",masterBasicRoomId);
                                                compareHotelBasicRoomMapper.updateByExampleSelective(compareHotelBasicRoom,example);
                                            }
                                        }
                                    }else{
                                        //如果效验数据一样就跳过
                                        if(compareHotelBasicRoomold.getMtHotelRoomId().equals(String.valueOf(mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId()))){
                                            log.info("=============数据一致直接跳过===================");
                                            continue switchTab;
                                        }else{//出现房型id不一样就进行更新
                                            log.info("==================数据不一样的=========");
                                            compareHotelBasicRoom=new CompareHotelBasicRoom();
                                            compareHotelBasicRoom.setCreateTime(new Date());
                                            compareHotelBasicRoom.setModifyTime(new Date());
                                            compareHotelBasicRoom.setId(StringUtil.getUUID());
                                            compareHotelBasicRoom.setIsCompare(1);
                                            compareHotelBasicRoom.setModifyTime(new Date());
                                            compareHotelBasicRoom.setMtHotelId(String.valueOf(mtHotelId));
                                            compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId()));
                                            compareHotelBasicRoom.setMtRoomName(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName());
                                            compareHotelBasicRoom.setSwitchRoomName(switchBasicRoomType.getBasicRoomName());
                                            compareHotelBasicRoom.setRemark("");
                                            compareHotelBasicRoom.setState(0);
                                            compareHotelBasicRoom.setCreateState(0);
                                            compareHotelBasicRoom.setSwitchHotelId(switchBasicRoomType.getHotelId());
                                            compareHotelBasicRoom.setSwitchMasterHotelId(switchBasicRoomType.getMasterHotelId());
                                            compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(masterBasicRoomId));
                                            Example example=new Example(CompareHotelBasicRoom.class);
                                            Example.Criteria criteria=example.createCriteria();
                                            criteria.andEqualTo("switchHotelId",switchBasicRoomType.getHotelId());
                                            criteria.andEqualTo("switchHotelRoomId",masterBasicRoomId);
                                            compareHotelBasicRoomMapper.updateByExampleSelective(compareHotelBasicRoom,example);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }else{
                log.info("=================走单独获取美团房型列表数据接口===========");
                key="compare_meituan_hotel_room_"+mtHotelId;
                List<MtRoomInfoDto> list=new ArrayList<>();
                if(redisService.exists(key)){
                    String json= (String) redisService.get(key);
                    list= JacksonUtil.jsonToList(json,MtRoomInfoDto.class);
                }else{
                    //获取美团酒店的房型列表
                    String url = CommonUrlConstants.MEITUAN_HOST + CompareRequestUrlEnums.GET_MEI_TUAN_HOTEL_ROOM_LIST.getUrl();
                    Map<String, Object> params=new HashMap<>();
                    params.put("mtHotelId",mtHotelId.toString());
                    try {
                        Result<List<MtRoomInfoDto>> result = compareRestTempaleUtilsService.sendPostToMeiTuanHotelRoomList(url, params);
                        if (result.getCode() == CommonConstants.SUCCESS) {
                            log.info("=====请求获取效验房型控制器成功,美团的房型数据为{}=======", result.getData());
                            list=result.getData();
                            if(!ObjectUtils.isEmpty(list)){
                                redisService.set(key, JSON.toJSONString(list),(long)20000);
                            }
                        }
                    } catch (Exception e) {
                        log.info("===============发生异常====================");
                    }
                }
                if(!ObjectUtils.isEmpty(siwtchHotelId)){
                    SwitchBasicRoomType switchRoomType=new SwitchBasicRoomType();
                    //母酒店id
                    switchRoomType.setMasterHotelId(siwtchHotelId);
                    List<SwitchBasicRoomType> switchRoomTypes=switchBasicRoomTypeMapper.select(switchRoomType);
                    log.info("=========携程的房型列表为{}=========",switchRoomTypes.toString());
                    if(!ObjectUtils.isEmpty(list)&&list.size()>0){
                        CompareHotelBasicRoom compareHotelBasicRoom;
                        tab:for(MtRoomInfoDto mtRoomInfoDto:list){
                            log.info("==========遍历开始数据为{}====",mtRoomInfoDto.toString());
                            String basicRoomName="";
                            StringBuilder mtRoomName= new StringBuilder(mtRoomInfoDto.getRoomName().replaceAll(" ", "").replaceAll("\\(", "").replaceAll("\\)", "").replaceAll("3", "三").replaceAll("4", "四"));
                            switchTab:for(SwitchBasicRoomType switchBasicRoomType:switchRoomTypes){
                                basicRoomName=switchBasicRoomType.getBasicRoomName();
                                String siwtchRoomName=switchBasicRoomType.getBasicRoomName().replaceAll(" ","").replaceAll("\\(","").replaceAll("\\)","").replaceAll("3","三").replaceAll("4","四");;
                                if(mtRoomName.toString().equals(siwtchRoomName)){
                                    Integer masterBasicRoomId=switchBasicRoomType.getMasterBasicRoomId();
                                    //如果是无窗
                                    if(mtRoomInfoDto.getWindow()==2){
                                        mtRoomName.append("(无窗)");
                                        for(SwitchBasicRoomType switchBasicRoomType1:switchRoomTypes){
                                            String roomName=switchBasicRoomType1.getBasicRoomName().replaceAll(" ","").replaceAll("\\(","").replaceAll("\\)","").replaceAll("3","三").replaceAll("4","四");
                                            if(mtRoomName.toString().equals(roomName)){
                                                basicRoomName=switchBasicRoomType1.getBasicRoomName();
                                                log.info("=========美团的物理房型为无窗，找到携程有无窗房型进行映射=================");
                                                masterBasicRoomId=switchBasicRoomType1.getMasterBasicRoomId();
                                                break ;
                                            }

                                        }
                                    }
                                    log.info("=======百分百一样=======");
                                    CompareHotelBasicRoom compareHotelBasicRoomold=compareHotelBasicRoomMapper.getHotelRoomInfo(switchBasicRoomType.getMasterHotelId(), masterBasicRoomId);
                                    //没有效验数据，就直接插入
                                    if(ObjectUtils.isEmpty(compareHotelBasicRoomold)){
                                        compareHotelBasicRoomold=compareHotelBasicRoomMapper.getHotelRoomInfoByMtHotelIdAndMtRoomId(mtHotelId, mtRoomInfoDto.getRoomId());
                                        if(ObjectUtils.isEmpty(compareHotelBasicRoomold)){
                                            log.info("===========不存在此数据================");
                                            compareHotelBasicRoom=new CompareHotelBasicRoom();
                                            compareHotelBasicRoom.setCreateTime(new Date());
                                            compareHotelBasicRoom.setId(StringUtil.getUUID());
                                            compareHotelBasicRoom.setIsCompare(1);
                                            compareHotelBasicRoom.setModifyTime(new Date());
                                            compareHotelBasicRoom.setMtHotelId(String.valueOf(mtHotelId));
                                            compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(mtRoomInfoDto.getRoomId()));
                                            compareHotelBasicRoom.setMtRoomName(mtRoomInfoDto.getRoomName());
                                            compareHotelBasicRoom.setSwitchRoomName(basicRoomName);
                                            compareHotelBasicRoom.setRemark("");
                                            compareHotelBasicRoom.setState(0);
                                            compareHotelBasicRoom.setCreateState(0);
                                            compareHotelBasicRoom.setSwitchHotelId(switchBasicRoomType.getHotelId());
                                            compareHotelBasicRoom.setSwitchMasterHotelId(switchBasicRoomType.getMasterHotelId());
                                            compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(masterBasicRoomId));
                                            compareHotelBasicRoomMapper.insert(compareHotelBasicRoom);
                                        }else{
                                            if(compareHotelBasicRoomold.getMtHotelRoomId().equals(String.valueOf(mtRoomInfoDto.getRoomId()))){
                                                log.info("=============数据一致直接跳过===================");
                                                continue switchTab;
                                            }else{//出现房型id不一样就进行更新
                                                log.info("==================数据不一样的=========");
                                                compareHotelBasicRoom=new CompareHotelBasicRoom();
                                                compareHotelBasicRoom.setCreateTime(new Date());
                                                compareHotelBasicRoom.setModifyTime(new Date());
                                                compareHotelBasicRoom.setId(StringUtil.getUUID());
                                                compareHotelBasicRoom.setIsCompare(1);
                                                compareHotelBasicRoom.setModifyTime(new Date());
                                                compareHotelBasicRoom.setMtHotelId(String.valueOf(mtHotelId));
                                                compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(mtRoomInfoDto.getRoomId()));
                                                compareHotelBasicRoom.setMtRoomName(mtRoomInfoDto.getRoomName());
                                                compareHotelBasicRoom.setSwitchRoomName(switchBasicRoomType.getBasicRoomName());
                                                compareHotelBasicRoom.setRemark("");
                                                compareHotelBasicRoom.setState(0);
                                                compareHotelBasicRoom.setCreateState(0);
                                                compareHotelBasicRoom.setSwitchHotelId(switchBasicRoomType.getHotelId());
                                                compareHotelBasicRoom.setSwitchMasterHotelId(switchBasicRoomType.getMasterHotelId());
                                                compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(masterBasicRoomId));
                                                Example example=new Example(CompareHotelBasicRoom.class);
                                                Example.Criteria criteria=example.createCriteria();
                                                criteria.andEqualTo("switchHotelId",switchBasicRoomType.getHotelId());
                                                criteria.andEqualTo("switchHotelRoomId",masterBasicRoomId);
                                                compareHotelBasicRoomMapper.updateByExampleSelective(compareHotelBasicRoom,example);
                                            }
                                        }
                                    }else{
                                        //如果效验数据一样就跳过
                                        if(compareHotelBasicRoomold.getMtHotelRoomId().equals(String.valueOf(mtRoomInfoDto.getRoomId()))){
                                            log.info("=============数据一致直接跳过===================");
                                            continue switchTab;
                                        }else{//出现房型id不一样就进行更新
                                            log.info("==================数据不一样的=========");
                                            compareHotelBasicRoom=new CompareHotelBasicRoom();
                                            compareHotelBasicRoom.setCreateTime(new Date());
                                            compareHotelBasicRoom.setModifyTime(new Date());
                                            compareHotelBasicRoom.setId(StringUtil.getUUID());
                                            compareHotelBasicRoom.setIsCompare(1);
                                            compareHotelBasicRoom.setModifyTime(new Date());
                                            compareHotelBasicRoom.setMtHotelId(String.valueOf(mtHotelId));
                                            compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(mtRoomInfoDto.getRoomId()));
                                            compareHotelBasicRoom.setMtRoomName(mtRoomInfoDto.getRoomName());
                                            compareHotelBasicRoom.setSwitchRoomName(switchBasicRoomType.getBasicRoomName());
                                            compareHotelBasicRoom.setRemark("");
                                            compareHotelBasicRoom.setState(0);
                                            compareHotelBasicRoom.setCreateState(0);
                                            compareHotelBasicRoom.setSwitchHotelId(switchBasicRoomType.getHotelId());
                                            compareHotelBasicRoom.setSwitchMasterHotelId(switchBasicRoomType.getMasterHotelId());
                                            compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(masterBasicRoomId));
                                            Example example=new Example(CompareHotelBasicRoom.class);
                                            Example.Criteria criteria=example.createCriteria();
                                            criteria.andEqualTo("switchHotelId",switchBasicRoomType.getHotelId());
                                            criteria.andEqualTo("switchHotelRoomId",masterBasicRoomId);
                                            compareHotelBasicRoomMapper.updateByExampleSelective(compareHotelBasicRoom,example);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }*/
        }
    }

    /***
    * @Author: lmf
    * @Date: 2020/9/29
     *通过sql语句进行房型效验 100%效验  在100%的基础上进行匹配
     * 过滤非重要字段["人"，“间","房","床"] + 房型包含括号的
    */
    public Result<Object> compareHotelBySqlAndRemoveSymbol(){
        return new Result<>();
    }


    /***
     * 根据vo获取对应携程-美团酒店下的房型
     */
    @Override
    public Result<Object> compareHotelRoomInfoByApi(CompareHotelRoomVo compareHotelRoomVo) {
        //判断vo是否为空
        if(ObjectUtils.isEmpty(compareHotelRoomVo.getHotelId())){
            return new Result<>(CommonConstants.SUCCESS);
        }

        //获取携程子酒店id
        Integer swHotelId = compareHotelRoomVo.getHotelId();



        List<Map<String,Object>> returnList = new ArrayList<>();

        //携程相关参数
        Map swMap = new HashMap();

        //美团相关参数
        Map mtMap = new HashMap();


        //根据携程子酒店id，获取母酒店id

        Example example = new Example(SwitchCreateRoomEntity.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("hotelId",swHotelId);

        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectByExample(example);

        List<Integer> switchRoomIds = new ArrayList<>();


        List<Long> mtHotelIds = new ArrayList<>();

        if(!switchCreateRoomEntities.isEmpty() && switchCreateRoomEntities.size()>0){
            for(int i=0;i<switchCreateRoomEntities.size();i++){
                SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomEntities.get(i);
                switchRoomIds.add(switchCreateRoomEntity.getRoomId());
                if(!ObjectUtils.isEmpty(switchCreateRoomEntity.getMtHotelId()) && mtHotelIds.size() ==0){
                    mtHotelIds.add(Long.valueOf(switchCreateRoomEntity.getMtHotelId()));
                }
            }
        }else{
            return null;
        }

        //调用携程查询房型相关接口

        Calendar calendar = Calendar.getInstance();
        String nowDate = DateUtil.getToday2();
        try {
            calendar.setTime(new SimpleDateFormat("yyyyMMdd").parse(nowDate));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        String startDate = "/Date("+calendar.getTimeInMillis()+"+0800)/";
        calendar.add(Calendar.DAY_OF_MONTH,1);//加1天
        String endDate = "/Date("+calendar.getTimeInMillis()+"+0800)/";

        swMap.put("channel","Ctrip");
        swMap.put("isGetPurchasePrice",false);
        swMap.put("hotelId",swHotelId);
        swMap.put("roomIds",switchRoomIds);
        swMap.put("startDate",startDate);
        swMap.put("endDate",endDate);

        String swUrl = CommonUrlConstants.SWITCHS_HOST+ "/switchRoomPrice/GetRoomPriceDirect";

        Result<Object> swObjectResult = RestTemplateUtils.post(swUrl, JacksonUtil.objectToJson(swMap),restTemplate);
        log.info("swObjectResult>>>>{}",JacksonUtil.objectToJson(swObjectResult));
        if(ObjectUtils.isEmpty(swObjectResult) || ObjectUtils.isEmpty(swObjectResult.getData())){
            return new Result<>(CommonEnums.DATA_NULL.getCode(),"调用携程获取房价接口，返回酒店数据为空！");
        }


        /////////////////////////////////查询携程房价信息end/////////////////////////////////////////////////

        String swStatusUrl = CommonUrlConstants.SWITCHS_HOST+ "/switchRoomPrice/GetRoomStatusDirect";


        Result<Object> swStatusObjectResult = RestTemplateUtils.post(swStatusUrl, JacksonUtil.objectToJson(swMap),restTemplate);
        log.info("swStatusObjectResult>>>>{}",JacksonUtil.objectToJson(swStatusObjectResult));
        if(ObjectUtils.isEmpty(swStatusObjectResult) || ObjectUtils.isEmpty(swStatusObjectResult.getData())){
            return new Result<>(CommonEnums.DATA_NULL.getCode(),"调用携程获取房态接口，返回酒店数据为空！");
        }

        /////////////////////////////////查询携程房态信息end/////////////////////////////////////////////////

        //调用美团查询酒店房型相关接口
        String checkinDate = DateUtil.getToday();
        String checkoutDate = DateUtil.getUpDate(checkinDate,-1);

//        mtMap.put("hotelIds",mtHotelIds);
//        mtMap.put("checkinDate",checkinDate);
//        mtMap.put("checkoutDate",checkoutDate);
//        mtMap.put("goodsType",1);

        MtHotelGoodsParamVo mtHotelGoodsParamVo = new MtHotelGoodsParamVo();

        mtHotelGoodsParamVo.setHotelIds(mtHotelIds);
        mtHotelGoodsParamVo.setCheckinDate(checkinDate);
        mtHotelGoodsParamVo.setCheckoutDate(checkoutDate);
        mtHotelGoodsParamVo.setGoodsType(1);


        String mtUrl = CommonUrlConstants.MEITUAN_HOST+"/mtHotelGoods/getMtHotelGoods";
//        String mtUrl = "http://192.168.1.113:4300/mtHotelGoods/getMtHotelGoods";

        Result<MtHotelGoodsVo> mtObjectResult = RestTemplateUtils.post(mtUrl, JacksonUtil.objectToJson(mtHotelGoodsParamVo),restTemplate);
        log.info("mtObjectResult>>{}",JacksonUtil.objectToJson(mtObjectResult));

        if(ObjectUtils.isEmpty(mtObjectResult) || ObjectUtils.isEmpty(mtObjectResult.getData())){
            return new Result<>(CommonEnums.DATA_NULL.getCode(),"调用美团接口，返回酒店数据为空！");
        }


        //获取价格比例
        priPre = (String) redisService.get(priKey);
        switchPriceBaseSetEntityByCtripChannel=JacksonUtil.parse(JacksonUtil.objectToJson(JacksonUtil.parse(priPre,Object.class)),List.class);

        //是否推送消息 true :推送； false :不推送
        boolean isMsg = false;

        for(int i=0;i<switchCreateRoomEntities.size();i++){
            Map<String,Object> returnMap = new HashMap<>();
            boolean isCompare = false;
            BigDecimal swPriPre = new BigDecimal(1);
            SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomEntities.get(i);
            Map<String,Object> swTempMap = getSwRoomInfoByReturn(switchCreateRoomEntity.getRoomId(),swObjectResult,swStatusObjectResult);
            if(ObjectUtils.isEmpty(swTempMap) && swTempMap.size() == 0){
                continue;
            }
            returnMap.putAll(swTempMap);
            Map<String,Object> mtTempMap = getMtGoodsINfoByReturn(switchCreateRoomEntity.getMtGoodId(),mtObjectResult);
            if(ObjectUtils.isEmpty(mtTempMap) && mtTempMap.size() == 0){
                continue;
            }
            returnMap.putAll(mtTempMap);
            returnMap.put("hotelId",switchCreateRoomEntity.getHotelId());
            returnMap.put("roomName",switchCreateRoomEntity.getRoomName());
            returnMap.put("mtHotelId",switchCreateRoomEntity.getMtHotelId());

            returnMap.put("switchRoomName",switchCreateRoomEntity.getSwitchRoomName());
            returnMap.put("mtRoomName",switchCreateRoomEntity.getMtRoomName());

            //使用的价格阶梯比例
            BigDecimal rate = new BigDecimal(1);
            BigDecimal swPrice = new BigDecimal(swTempMap.get("price").toString());
            //校验价格是否相等
            if(switchPriceBaseSetEntityByCtripChannel.size()>0){
                //获取价格阶梯比例
                for(int j=0;j<switchPriceBaseSetEntityByCtripChannel.size();j++) {
                    Map<String,Object> switchPriceBaseSetEntityByCtripChannelMap = JacksonUtil.parse(JacksonUtil.objectToJson(switchPriceBaseSetEntityByCtripChannel.get(j)),Map.class);
                    BigDecimal minPri = new BigDecimal(0);
                    BigDecimal maxPri = new BigDecimal(0);
                    if(!switchPriceBaseSetEntityByCtripChannelMap.isEmpty() && switchPriceBaseSetEntityByCtripChannelMap.size()>0){
                        minPri = new BigDecimal(switchPriceBaseSetEntityByCtripChannelMap.get("minPrice").toString());
                        maxPri = new BigDecimal(switchPriceBaseSetEntityByCtripChannelMap.get("maxPrice").toString());
                        rate = new BigDecimal(switchPriceBaseSetEntityByCtripChannelMap.get("rate").toString()).add(new BigDecimal(100)).divide(new BigDecimal(100),2, RoundingMode.HALF_UP);
                        //判断价格是否在此区间
                        if(swPrice.compareTo(minPri) > 0 && swPrice.compareTo(maxPri) <= 0){
                            break;
                        }

                    }

                }
            }
            if(!ObjectUtils.isEmpty(mtTempMap.get("mtPrice"))){
                BigDecimal mtBd = new BigDecimal(mtTempMap.get("mtPrice").toString()).multiply(rate).setScale(2,BigDecimal.ROUND_HALF_UP);

                log.info("mtBd.toPlainString()>>>{}",mtBd.toPlainString());
                returnMap.put("mtComparePrice",mtBd);
                if(mtBd.compareTo(swPrice) == 0){
                    //校验早餐数量是否一样
                    if(swTempMap.get("breakfast").equals(mtTempMap.get("mtBreakfastNum").toString())){
                        if(swTempMap.get("saleStatus").toString().equals(mtTempMap.get("mtGoodsStatus").toString())) {
//                        if(i == 1){
//                            isCompare = false;
//                        }else {
                            isCompare = true;
//                        }
                        }
                    }
                }
            }

            //当存在异常的酒店房型信息，推送钉钉消息
            if(!isCompare){
                isMsg = true;
            }
            returnMap.put("isCompare",isCompare);

            returnList.add(returnMap);
        }

        //推送钉钉消息
        if(isMsg){
            try {
                SendUtils.dingMsg("【房型比对-异常产品信息】", "携程酒店id:【" + swHotelId + "】及时关注！！！ ", MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(), restTemplate);
            }catch (Exception e){
                log.info("后台房型比对钉钉推送异常！");
            }
        }
        return new Result<>(returnList);
    }


    /**
     * 查询携程当天房型相关信息
     * @param swObjectResult 价格
     * @param swStatusObjectResult 房态
     * @return
     */
    public Map<String,Object> getSwRoomInfoByReturn(Integer roomId,Result<Object> swObjectResult,Result<Object> swStatusObjectResult){
        Map<String,Object> swReturn = new HashMap<>();
        Map<String,Object> swPricesReturn = new HashMap<>();
        Map<String,Object> swStatusReturn = new HashMap<>();

        if(!ObjectUtils.isEmpty(roomId) && !ObjectUtils.isEmpty(swObjectResult) && !ObjectUtils.isEmpty(swStatusObjectResult)){
            //对结构进行格式化
            Map<String,Object> getData = JacksonUtil.parse(JacksonUtil.objectToJson(swObjectResult.getData()),Map.class);
//            List<Map<String,Object>> swChannelRoomPricesList = JacksonUtil.parse(JacksonUtil.objectToJson(getData.get("channelRoomPrices")),List.class);
            List<Map<String,Object>>  channelRoomPricesList = JacksonUtil.parse(JacksonUtil.objectToJson(getData.get("channelRoomPrices")),List.class);
//            log.info(">>>>"+channelRoomPricesList);
            Map<String,Object> swChannelRoomPrices = JacksonUtil.parse(JacksonUtil.objectToJson(channelRoomPricesList.get(0)),Map.class);
            if(!ObjectUtils.isEmpty(swChannelRoomPrices)){
                //获取携程对应相关售卖房型信息
                List<Map<String,Object>> swRoomPricesList = JacksonUtil.parse(JacksonUtil.objectToJson(swChannelRoomPrices.get("roomPrices")),List.class);
                if(swRoomPricesList.size()>0){
                    a:for(int l=0;l<swRoomPricesList.size();l++){
                        Map<String,Object> roomPricesMap = swRoomPricesList.get(l);
                        if(roomPricesMap.size()>0){
                            for(Map.Entry<String, Object> entry : roomPricesMap.entrySet()){
                                String mapKey = entry.getKey();
                                Object mapValue = entry.getValue();
//                                System.out.println(mapKey+":"+mapValue);
                                if("roomId".equals(mapKey) ){
                                    BigDecimal db = new BigDecimal(mapValue.toString());
                                    if(db.compareTo(new BigDecimal(roomId)) == 0) {
                                        swPricesReturn = roomPricesMap;
                                        break a;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //对房态结构进行格式化
            List<Map<String,Object>> swChannelRoomStatusList = JacksonUtil.parse(JacksonUtil.objectToJson(swStatusObjectResult.getData()),List.class);
            if(!ObjectUtils.isEmpty(swChannelRoomStatusList) && swChannelRoomStatusList.size()>0){
                a:for(int l=0;l<swChannelRoomStatusList.size();l++){
                    Map<String,Object> roomStatusMap = swChannelRoomStatusList.get(l);
                    if(roomStatusMap.size()>0){
                        for(Map.Entry<String, Object> entry : roomStatusMap.entrySet()){
                            String mapKey = entry.getKey();
                            Object mapValue = entry.getValue();
//                            System.out.println(mapKey+":"+mapValue);
                            if("roomId".equals(mapKey) ){
                                BigDecimal db = new BigDecimal(mapValue.toString());
                                if(db.compareTo(new BigDecimal(roomId)) == 0) {
                                    swStatusReturn = roomStatusMap;
                                    break a;
                                }
                            }
                        }
                    }
                }
            }

        }

        if(swPricesReturn.size()>0 && swStatusReturn.size()>0){
            for(Map.Entry<String, Object> entry : swPricesReturn.entrySet()){
                String mapKey = entry.getKey();
                Object mapValue = entry.getValue();
                if("roomId".equals(mapKey) || "price".equals(mapKey) || "breakfast".equals(mapKey)){

                    if("roomId".equals(mapKey) ){
                        BigDecimal db = new BigDecimal(mapValue.toString());
                        mapValue = db.toPlainString();
                    }

                    if("breakfast".equals(mapKey)){
                        if(new BigDecimal(String.valueOf(mapValue)).compareTo(new BigDecimal(0)) == 0){
                            mapValue = "无早";
                        }else if(new BigDecimal(String.valueOf(mapValue)).compareTo(new BigDecimal(1)) == 0){
                            mapValue = "单早";
                        }else if(new BigDecimal(String.valueOf(mapValue)).compareTo(new BigDecimal(2)) == 0){
                            mapValue = "双早";
                        }else{
                            mapValue= new BigDecimal(mapValue.toString()).toPlainString()+ "早";
                        }
                    }

                    swReturn.put(mapKey,mapValue);
                }
            }

            for(Map.Entry<String, Object> entry : swStatusReturn.entrySet()){
                String mapKey = entry.getKey();
                Object mapValue = entry.getValue();
                if("saleStatus".equals(mapKey)){
                    //房态:0满房1销售2限量
                    if(new BigDecimal(mapValue.toString()).compareTo(new BigDecimal(0)) == 0){
                        swReturn.put(mapKey,"满房");
                    }else{
                        swReturn.put(mapKey,"有房");
                    }
                }
            }
        }


        log.debug("swReturn>>{}",JacksonUtil.objectToJson(swReturn));

        return swReturn;
    }

    /**
     * 根据产品id 获取对应产品相关信息
     * @param goodsId
     * @param mtObjectResult
     * @return
     */
    public Map<String,Object> getMtGoodsINfoByReturn(Integer goodsId,Result<MtHotelGoodsVo> mtObjectResult){
        Map<String,Object> mtResultMap = new HashMap<>();
        Map<String,Object> mtGoodsMap = new HashMap<>();

        Map<String,Object> getData = JacksonUtil.parse(JacksonUtil.objectToJson(mtObjectResult.getData()),Map.class);
        if(!ObjectUtils.isEmpty(goodsId) && !ObjectUtils.isEmpty(mtObjectResult)){
            List hotelGoods = (List) getData.get("hotelGoods");
            Map<String,Object> hotelGoodsMap = JacksonUtil.parse(JacksonUtil.objectToJson(hotelGoods.get(0)),Map.class);
            List goods = JacksonUtil.parse(JacksonUtil.objectToJson(hotelGoodsMap.get("goods")),List.class);
            if(!ObjectUtils.isEmpty(goods) && goods.size()>0){
                a:for(int l=0;l<goods.size();l++){
                    Map<String,Object> goodsMap = JacksonUtil.parse(JacksonUtil.objectToJson(goods.get(l)),Map.class);
                    if(goodsMap.size()>0){
                        for(Map.Entry<String, Object> entry : goodsMap.entrySet()){
                            String mapKey = entry.getKey();
                            Object mapValue = entry.getValue();
//                            System.out.println(mapKey+":"+mapValue);
                            if("goodsId".equals(mapKey) ){
                                BigDecimal db = new BigDecimal(mapValue.toString());
                                log.info("goodsId>>>>>>>{}---mapValue>>>{}",goodsId,mapValue.toString());
                                if(db.compareTo(new BigDecimal(goodsId)) == 0) {
                                    mtGoodsMap = goodsMap;
                                    break a;
                                }
                            }
                        }
                    }
                }
            }
        }

        if(!ObjectUtils.isEmpty(mtGoodsMap) && mtGoodsMap.size()>0){
            mtResultMap.put("mtGoodsId",mtGoodsMap.get("goodsId"));
            mtResultMap.put("mtGoodsName",mtGoodsMap.get("goodsName"));

            if(new BigDecimal(mtGoodsMap.get("goodsStatus").toString()).compareTo(new BigDecimal(1)) == 0){
                mtResultMap.put("mtGoodsStatus","有房");
            }else{
                mtResultMap.put("mtGoodsStatus","满房");
            }
//            mtResultMap.put("mtGoodsStatus",mtGoodsMap.get("goodsStatus"));

//            log.info(">>>>>>>>>>>>>>>>>>{}",JacksonUtil.objectToJson(mtGoodsMap.get("breakFast")));
            List breakFast = JacksonUtil.parse(JacksonUtil.objectToJson(mtGoodsMap.get("breakFast")),List.class);
            if(breakFast.size()>0){
                Map<String,Object> mtHotelGoodsBreakfastMap = JacksonUtil.parse(JacksonUtil.objectToJson(breakFast.get(0)),Map.class);
                if(new BigDecimal(mtHotelGoodsBreakfastMap.get("breakfastType").toString()).compareTo(new BigDecimal(1)) == 0){
                    if(new BigDecimal(mtHotelGoodsBreakfastMap.get("breakfastNum").toString()).compareTo(new BigDecimal(1)) == 0){
                        mtResultMap.put("mtBreakfastNum","单早");
                    }else if(new BigDecimal(mtHotelGoodsBreakfastMap.get("breakfastNum").toString()).compareTo(new BigDecimal(2)) == 0){
                        mtResultMap.put("mtBreakfastNum","双早");
                    }else{
                        mtResultMap.put("mtBreakfastNum",new BigDecimal(mtHotelGoodsBreakfastMap.get("breakfastNum").toString()).toPlainString()+"早");
                    }
                }else {
                    mtResultMap.put("mtBreakfastNum","无早");
                }
            }

            List priceModels = JacksonUtil.parse(JacksonUtil.objectToJson(mtGoodsMap.get("priceModels")),List.class);
            if(priceModels.size()>0){
                Map<String,Object> priceModelsMap = JacksonUtil.parse(JacksonUtil.objectToJson(priceModels.get(0)),Map.class);
                double mtPriceDb = Double.valueOf(priceModelsMap.get("salePrice").toString()) - Double.valueOf(priceModelsMap.get("subPrice").toString());
                BigDecimal bg = new BigDecimal(mtPriceDb);
                double mtPrice = bg.divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP).doubleValue();
                mtResultMap.put("mtPrice", mtPrice);
            }
        }
        return mtResultMap;
    }


    /***
     * 根据vo获取对应携程-美团酒店下的房型
     */
    @Override
    public Result<Object> compareHotelRoomInfoByAllUpHotel() {
        List<Integer> switchCreateRoomEntities = switchCreateRoomMapper.getHotelIds();
        new Thread(new Runnable() {
            @Override
            public void run() {
                if(!ObjectUtils.isEmpty(switchCreateRoomEntities) && switchCreateRoomEntities.size()>0){
                    switchCreateRoomEntities.forEach(hotelId -> {
                        CompareHotelRoomVo compareHotelRoomVo = new CompareHotelRoomVo();
                        compareHotelRoomVo.setHotelId(hotelId);
//                        log.info("hotelId>>>{}",hotelId);
                        Result<Object> result =  compareHotelRoomInfoByApi(compareHotelRoomVo);
                    });
                }
            }
        });
        return new Result<>(CommonConstants.SUCCESS,"接口调用成功！");
    }


    /***
    * @Author: lmf
    * @Date: 2020/12/24
     * 根据美团酒店id获取房型重新进行比例
     * @return
    */
    public MtHotelRoomVo compareHotelRoomByInterface(MtHotelRoomVo mtHotelRoomVo, Integer masterHotelId, Integer roomId){
        String key="compare_meituan_hotel_room_"+mtHotelRoomVo.getMtHotelId();
        List<MtRoomInfoDto> list=new ArrayList<>();
        if(redisService.exists(key)){
            String json= (String) redisService.get(key);
            list= JacksonUtil.jsonToList(json,MtRoomInfoDto.class);
        }else{
            //获取美团酒店的房型列表
            String url = CommonUrlConstants.MEITUAN_HOST + CompareRequestUrlEnums.GET_MEI_TUAN_HOTEL_ROOM_LIST.getUrl();
            Map<String, Object> params=new HashMap<>();
            params.put("mtHotelId",mtHotelRoomVo.getMtHotelId().toString());
            try {
                Result<List<MtRoomInfoDto>> result = compareRestTempaleUtilsService.sendPostToMeiTuanHotelRoomList(url, params);
                if (result.getCode() == CommonConstants.SUCCESS) {
                    log.info("=====请求获取效验房型控制器成功,美团的房型数据为{}=======", result.getData());
                    list=result.getData();
                    if(!ObjectUtils.isEmpty(list)){
                        redisService.set(key, JSON.toJSONString(list),(long)20000);
                    }
                }
            } catch (Exception e) {
                log.info("===============发生异常====================");
            }
        }
        log.info("===================进来了=====================");
        if(!ObjectUtils.isEmpty(list)&&list.size()>0){
            for(MtRoomInfoDto mtRoomInfoDto:list){
                //返回最新的房型id
                String mtRoomName=mtHotelRoomVo.getMtRoomName().replaceAll(" ","").replaceAll("\\(","").replaceAll("\\)","").replaceAll("3","三").replaceAll("4","四");
                String mtRoomNameInterFace=mtRoomInfoDto.getRoomName().replaceAll(" ","").replaceAll("\\(","").replaceAll("\\)","").replaceAll("3","三").replaceAll("4","四");
                if(mtRoomName.equals(mtRoomNameInterFace)){
                    log.info("============数据库的房型名称为{},接口返回的房型名称为{}==",mtHotelRoomVo.getMtRoomName(),mtRoomInfoDto.getRoomName());
                    log.info("==========房型名称没有变更=======");
                    if(mtHotelRoomVo.getMtRoomId().intValue()==mtRoomInfoDto.getRoomId().intValue()){
                        log.info("==========房型id没有变更===========");
                        return mtHotelRoomVo;
                    }else{//房型id变更，就进行更新
                        CompareHotelBasicRoom compareHotelBasicRoom=new CompareHotelBasicRoom();
                        compareHotelBasicRoom.setCreateTime(new Date());
                        compareHotelBasicRoom.setModifyTime(new Date());
                        compareHotelBasicRoom.setId(StringUtil.getUUID());
                        compareHotelBasicRoom.setIsCompare(1);
                        compareHotelBasicRoom.setModifyTime(new Date());
                        compareHotelBasicRoom.setMtHotelId(String.valueOf(mtHotelRoomVo.getMtHotelId()));
                        compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(mtRoomInfoDto.getRoomId()));
                        compareHotelBasicRoom.setMtRoomName(mtRoomInfoDto.getRoomName());
                        compareHotelBasicRoom.setRemark("");
                        compareHotelBasicRoom.setState(0);
                        compareHotelBasicRoom.setCreateState(0);
                        Example example=new Example(CompareHotelBasicRoom.class);
                        Example.Criteria criteria=example.createCriteria();
                        criteria.andEqualTo("switchMasterHotelId",masterHotelId);
                        criteria.andEqualTo("switchHotelRoomId",roomId);
                        compareHotelBasicRoomMapper.updateByExampleSelective(compareHotelBasicRoom,example);
                        mtHotelRoomVo.setMtRoomId(mtRoomInfoDto.getRoomId());
                        return mtHotelRoomVo;
                    }
                }
            }
        }
        return null;
    }
    /***
    * @Author: lmf
    * @Date: 2021/1/13
     * 检查上架的酒店是否有房型数据
    */
    @Override
    public Result<Object> checkHotelIsCreateData() {
        List<SwitchHotelUpEntity> switchHotelUpEntities=switchHotelUpMapper.selectSaleList();
        for(SwitchHotelUpEntity switchHotelUpEntity:switchHotelUpEntities){
           List<Integer> compareList=compareHotelBasicRoomMapper.selectNoCreateBasicRoom(switchHotelUpEntity.getHotelId());
           if(!ObjectUtils.isEmpty(compareList)&&compareList.size()>0){
               compareHotelBasicRoomMapper.updateHotelBasicRoomState(compareList);
               try {
                   Thread.sleep(200);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        }
        return null;
    }
    /***
    * @Author: lmf
    * @Date: 2021/1/20
    */
    @Override
    public Result<Object> compareRoomList(Integer masterHotelId, Integer mtHotelId) {
        //获取携程未匹配的房型列表
        List<SwitchBasicRoomType> switchBasicRoomTypes=switchBasicRoomTypeMapper.selectNoCompareListByHotelId(masterHotelId);
        List<SwitchHotelRoomVo> switchHotelRoomVos=new ArrayList<>();
        Map<String,Double> doubleMap=new HashMap<>();
        String url = CommonUrlConstants.MEITUAN_HOST + CompareRequestUrlEnums.GET_MEI_TUAN_HOTEL_ROOM_REUTRN_LIST.getUrl();
        Map<String, Object> params=new HashMap<>();
        params.put("hotelId",mtHotelId.toString());
        List<MtHotelRealRoomVo> list=new ArrayList<>();
        try {
            Result<List<MtHotelRealRoomVo>> result = compareRestTempaleUtilsService.sendPostToMeiTuanHotelRoomReturnList(url, params);
            if (result.getCode() == CommonConstants.SUCCESS) {
                log.info("=====请求获取效验房型控制器成功,美团的房型数据为{}=======", result.getData());
                list=result.getData();
            }
        } catch (Exception e) {
            log.info("===============发生异常====================");
        }
        if(ObjectUtils.isEmpty(list)||list.size()<1){
            return new Result<>(switchHotelRoomVos);
        }
        for(SwitchBasicRoomType switchBasicRoomType:switchBasicRoomTypes){
            List<MtHotelRealRoomVo> list1=new ArrayList<>();
            List<SwitchMtHotelRoomInfo> list3=new ArrayList<>();
            tab:for(MtHotelRealRoomVo mtHotelRealRoomVo:list){
                Example example=new Example(CompareHotelBasicRoom.class);
                Example.Criteria criteria=example.createCriteria();
                criteria.andEqualTo("mtHotelRoomId",mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId());
                criteria.andEqualTo("mtHotelId",mtHotelId);
                int count=compareHotelBasicRoomMapper.selectCountByExample(example);
                if(count>0){
                    continue tab;
                }
                double similar=getSimilarRate(switchBasicRoomType.getBasicRoomName(),mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName());
                log.info("======携程房型为{},美团房型为{},相似程度为{}========",switchBasicRoomType.getBasicRoomName(),mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName(),similar);
                doubleMap.put(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName(),similar);
                list1.add(mtHotelRealRoomVo);
            }
            List<Map.Entry<String, Double>> list2 = new ArrayList<>(doubleMap.entrySet());
            // 默认的是从小到大排序，
            Collections.sort(list2, (o1, o2) -> {
                // 从大到小排序
                return (int) (o2.getValue() - o1.getValue());
            });
            int j=0;
            for(int i=0;i<list2.size();i++){
                if(j>2){
                    break;
                }
                String name=list2.get(i).getKey();
                for(MtHotelRealRoomVo mtHotelRealRoomVo:list1){
                    if(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName().equals(name)){
                        SwitchMtHotelRoomInfo mtHotelRoomInfo=new SwitchMtHotelRoomInfo();
                        mtHotelRoomInfo.setMtHotelRealRoomVo(mtHotelRealRoomVo);
                        mtHotelRoomInfo.setSimilar((int) (list2.get(i).getValue()*100));
                        list3.add(mtHotelRoomInfo);
                    }
                }
                j++;
            }
            SwitchHotelRoomVo switchHotelRoomVo=new SwitchHotelRoomVo();
            switchHotelRoomVo.setSwitchBasicRoomType(switchBasicRoomType);
            switchHotelRoomVo.setSwitchMtHotelRoomInfos(list3);
            switchHotelRoomVos.add(switchHotelRoomVo);
          /*  //获取美团的房型列表
            String key=CommonConstants.SWITCH_MT_ONE_HOTEL_ROOMS_REDIS+mtHotelId.toString();
            if(redisService.exists(key)) {
                String json = (String) redisService.get(key);
               *//* List<MtHotelRealRoomVo> list = GsonUtils.jsonToList(json, MtHotelRealRoomVo.class);*//*
                List<MtHotelRealRoomVo> list1=new ArrayList<>();
                List<SwitchMtHotelRoomInfo> list3=new ArrayList<>();
                tab:for(MtHotelRealRoomVo mtHotelRealRoomVo:list){
                      Example example=new Example(CompareHotelBasicRoom.class);
                      Example.Criteria criteria=example.createCriteria();
                      criteria.andEqualTo("mtHotelRoomId",mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId());
                      criteria.andEqualTo("mtHotelId",mtHotelId);
                      int count=compareHotelBasicRoomMapper.selectCountByExample(example);
                      if(count>0){
                         continue tab;
                      }
                      double similar=getSimilarRate(switchBasicRoomType.getBasicRoomName(),mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName());
                      log.info("======携程房型为{},美团房型为{},相似程度为{}========",switchBasicRoomType.getBasicRoomName(),mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName(),similar);
                      doubleMap.put(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName(),similar);
                      list1.add(mtHotelRealRoomVo);
                }
                List<Map.Entry<String, Double>> list2 = new ArrayList<>(doubleMap.entrySet());
                // 默认的是从小到大排序，
                Collections.sort(list2, (o1, o2) -> {
                    // 从大到小排序
                    return (int) (o2.getValue() - o1.getValue());
                });
                int j=0;
                for(int i=0;i<list2.size();i++){
                    if(j>2){
                        break;
                    }
                    String name=list2.get(i).getKey();
                    for(MtHotelRealRoomVo mtHotelRealRoomVo:list1){
                        if(mtHotelRealRoomVo.getRealRoomBaseInfo().getRoomName().equals(name)){
                            SwitchMtHotelRoomInfo mtHotelRoomInfo=new SwitchMtHotelRoomInfo();
                            mtHotelRoomInfo.setMtHotelRealRoomVo(mtHotelRealRoomVo);
                            mtHotelRoomInfo.setSimilar((int) (list2.get(i).getValue()*100));
                            list3.add(mtHotelRoomInfo);
                        }
                    }
                    j++;
                }
                SwitchHotelRoomVo switchHotelRoomVo=new SwitchHotelRoomVo();
                switchHotelRoomVo.setSwitchBasicRoomType(switchBasicRoomType);
                switchHotelRoomVo.setSwitchMtHotelRoomInfos(list3);
                switchHotelRoomVos.add(switchHotelRoomVo);
            }else{
                SwitchHotelRoomVo switchHotelRoomVo=new SwitchHotelRoomVo();
                switchHotelRoomVo.setSwitchBasicRoomType(switchBasicRoomType);
                switchHotelRoomVo.setSwitchMtHotelRoomInfos(new ArrayList<>());
                switchHotelRoomVos.add(switchHotelRoomVo);
            }*/
        }
        return new Result<>(switchHotelRoomVos);
    }
    /***
    * @Author: lmf
    * @Date: 2021/1/20
     * 计算俩个字符串的相似比例
    */
    public double getSimilarRate(String switchRoomName,String mtRoomName){
        int similar=0;
        char[] chars=switchRoomName.toCharArray();
        char[] chars1=mtRoomName.toCharArray();
        for (char aChar : chars) {
            for (char c : chars1) {
                if (aChar == c) {
                    similar++;
                }
            }
        }
        double bg = new BigDecimal((float)similar/chars.length).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return bg;
    }
    /***
    * @Author: lmf
    * @Date: 2021/1/21
     * 初步匹配成功
    */
    @Override
    public Result<Object> compareSuccess(CompareHotelRoomVo compareHotelRoomVo) {
        Example example=new Example(CompareHotelBasicRoom.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("switchHotelId",compareHotelRoomVo.getRoomId());
        criteria.andEqualTo("switchHotelRoomId",compareHotelRoomVo.getHotelId());
        int count=compareHotelBasicRoomMapper.selectCountByExample(example);
        if(count>0){
            return new Result<>();
        }
        if(ObjectUtils.isEmpty(compareHotelRoomVo.getMtRoomName())){
            return new Result<>("请提交有效的数据进行匹配");
        }
        CompareHotelBasicRoom compareHotelBasicRoom=new CompareHotelBasicRoom();
        compareHotelBasicRoom.setCreateTime(new Date());
        compareHotelBasicRoom.setId(StringUtil.getUUID());
        compareHotelBasicRoom.setIsCompare(5);
        compareHotelBasicRoom.setModifyTime(new Date());
        compareHotelBasicRoom.setMtHotelId(String.valueOf(compareHotelRoomVo.getMtHotelId()));
        compareHotelBasicRoom.setMtHotelRoomId(String.valueOf(compareHotelRoomVo.getMtRoomId()));
        compareHotelBasicRoom.setMtRoomName(compareHotelRoomVo.getMtRoomName());
        compareHotelBasicRoom.setSwitchRoomName(compareHotelRoomVo.getRoomName());
        compareHotelBasicRoom.setRemark("人工效验初步通过");
        compareHotelBasicRoom.setState(0);
        compareHotelBasicRoom.setCreateState(0);
        compareHotelBasicRoom.setSwitchHotelId(compareHotelRoomVo.getHotelId());
        compareHotelBasicRoom.setSwitchMasterHotelId(compareHotelRoomVo.getMasterHotelId());
        compareHotelBasicRoom.setSwitchHotelRoomId(String.valueOf(compareHotelRoomVo.getRoomId()));
        int flag=compareHotelBasicRoomMapper.insert(compareHotelBasicRoom);
        if(flag>0){
            return new Result<>();
        }else{
            return new Result<>("匹配失败");
        }
    }
    /***
    * @Author: lmf
    * @Date: 2021/1/22
     * 人工匹配完成
    */
    @Override
    public Result<Object> finshCompre(CompareHotelRoomVo compareHotelRoomVo) {
        Example example=new Example(CompareHotelBasicRoom.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("switchHotelId",compareHotelRoomVo.getHotelId());
        criteria.andEqualTo("isCompare",5);
        List<CompareHotelBasicRoom> compareHotelBasicRooms=compareHotelBasicRoomMapper.selectByExample(example);
        if(ObjectUtils.isEmpty(compareHotelBasicRooms)||compareHotelBasicRooms.size()<0){
            return new Result<>();
        }
        List<SwitchHotelRoomVo> switchHotelRoomVos=new ArrayList<>();
        for(CompareHotelBasicRoom compareHotelBasicRoom:compareHotelBasicRooms){
            //获取美团的房型列表
            String key=CommonConstants.SWITCH_MT_ONE_HOTEL_ROOMS_REDIS+compareHotelRoomVo.getMtHotelId().toString();
            if(redisService.exists(key)) {
                String json = (String) redisService.get(key);
                List<MtHotelRealRoomVo> list = GsonUtils.jsonToList(json, MtHotelRealRoomVo.class);
                List<SwitchMtHotelRoomInfo> list3=new ArrayList<>();
                tab:for(MtHotelRealRoomVo mtHotelRealRoomVo:list){
                    if(mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId().toString().equals(compareHotelBasicRoom.getMtHotelRoomId())){
                        log.info("===========一样的房型有{},{}==============",mtHotelRealRoomVo.getRealRoomBaseInfo().getRealRoomId(),compareHotelBasicRoom.getMtHotelRoomId());
                        SwitchMtHotelRoomInfo switchMtHotelRoomInfo=new SwitchMtHotelRoomInfo();
                        switchMtHotelRoomInfo.setSimilar(100);
                        switchMtHotelRoomInfo.setMtHotelRealRoomVo(mtHotelRealRoomVo);
                        list3.add(switchMtHotelRoomInfo);
                        SwitchHotelRoomVo switchHotelRoomVo=new SwitchHotelRoomVo();
                        SwitchBasicRoomType switchBasicRoomType=new SwitchBasicRoomType();
                        switchBasicRoomType.setBasicRoomName(compareHotelBasicRoom.getSwitchRoomName());
                        switchBasicRoomType.setMasterBasicRoomId(Integer.valueOf(compareHotelBasicRoom.getSwitchHotelRoomId()));
                        switchHotelRoomVo.setSwitchBasicRoomType(switchBasicRoomType);
                        switchHotelRoomVo.setSwitchMtHotelRoomInfos(list3);
                        switchHotelRoomVos.add(switchHotelRoomVo);
                    }
                }

            }
        }
        return new Result<>(switchHotelRoomVos);
    }
    /****
    * @Author: lmf
    * @Date: 2021/1/22
     * 放回重新进行匹配
    */
    @Override
    public Result<Object> recompre(CompareHotelRoomVo compareHotelRoomVo) {
        Example example=new Example(CompareHotelBasicRoom.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("switchHotelId",compareHotelRoomVo.getHotelId());
        criteria.andEqualTo("switchHotelRoomId",compareHotelRoomVo.getRoomId());
        int result=compareHotelBasicRoomMapper.deleteByExample(example);
        if(result>0){
            return new Result<>();
        }else{
            return new Result<>("删除失败");
        }

    }
    /***
    * @Author: lmf
    * @Date: 2021/1/22
     * 提交匹配
    */
    @Override
    public Result<Object> commitCompare(CompareHotelRoomVo compareHotelRoomVo) {
        Example example=new Example(CompareHotelBasicRoom.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("switchHotelId",compareHotelRoomVo.getHotelId());
        criteria.andEqualTo("switchHotelRoomId",compareHotelRoomVo.getRoomId());
        CompareHotelBasicRoom compareHotelBasicRoom=new CompareHotelBasicRoom();
        compareHotelBasicRoom.setIsCompare(1);
        compareHotelBasicRoom.setRemark("人工确认最后可以提交创建");
        int result=compareHotelBasicRoomMapper.updateByExampleSelective(compareHotelBasicRoom,example);
        if(result>0){
            return new Result<>();
        }else{
            return new Result<>("删除失败");
        }
    }
    /***
    * @Author: lmf
    * @Date: 2021/1/22
     * 一键
    */
    @Override
    public Result<Object> allCompare(GetRoomListVO getRoomListVO) {
        List<Integer> roomIds=getRoomListVO.getRoomIds();
        int result=compareHotelBasicRoomMapper.updateBatch(roomIds);
        if(result>0){
            return new Result<>();
        }else{
            return new Result<>("提交失败");
        }
    }
    /***
    * @Author: lmf
    * @Date: 2021/2/3
     * 根据携程的酒店id+携程的母物理房型id删除映射关系
    */
    @Override
    public Result<Object> removeHotelRoomInfoByHotelIdAndRoomId(int hotelId, int masterBaiscRoomId) {
        CompareHotelBasicRoom compareHotelBasicRoom = compareHotelBasicRoomMapper.getHotelRoomInfoByHotelIdAndRoomId(hotelId, masterBaiscRoomId);
        if(ObjectUtil.isEmpty(compareHotelBasicRoom)){
            return new Result<>();
        }else{
            CompareHotelRoom compareHotelRoom=new CompareHotelRoom();
            BeanUtils.copyProperties(compareHotelBasicRoom, compareHotelRoom);
            compareHotelRoom.setId(compareHotelRoom.getId()+ StringUtil.getFourRandom());
            compareHotelRoom.setCreateTime(new Date());
            int flag=compareHotelRoomMapper.insert(compareHotelRoom);
            if(flag>0){
                int f=compareHotelBasicRoomMapper.removeHotelRoomInfoByHotelIdAndRoomId(hotelId, masterBaiscRoomId);
                if(f>0){
                    return new Result<>();
                }else{
                    return new Result<>("清除失败");
                }
            }
            return new Result<>();
        }
    }

}
